Skip to content

Commit

Permalink
Add solution 0494
Browse files Browse the repository at this point in the history
  • Loading branch information
halfrost authored and dezhiy committed Nov 14, 2021
1 parent 3024684 commit d9a9759
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 25 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@
| | Easy | Medium | Hard | Total |
|:--------:|:--------:|:--------:|:--------:|:--------:|
|Optimizing|33|45|30|108|
|Accepted|**279**|**426**|**126**|**831**|
|Accepted|**280**|**426**|**126**|**832**|
|Total|527|1107|442|2076|
|Perfection Rate|88.2%|89.4%|76.2%|87.0%|
|Completion Rate|52.9%|38.5%|28.5%|40.0%|
|Completion Rate|53.1%|38.5%|28.5%|40.1%|
|------------|----------------------------|----------------------------|----------------------------|----------------------------|

## 二. 目录

以下已经收录了 726 道题的题解,还有 11 道题在尝试优化到 beats 100%
以下已经收录了 727 道题的题解,还有 11 道题在尝试优化到 beats 100%

| No. | Title | Solution | Acceptance | Difficulty | Frequency |
|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
Expand Down Expand Up @@ -633,7 +633,7 @@
|0492|Construct the Rectangle|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0492.Construct-the-Rectangle)|51.8%|Easy||
|0493|Reverse Pairs|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0493.Reverse-Pairs)|28.9%|Hard||
|0494|Target Sum|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0494.Target-Sum)|45.3%|Medium||
|0495|Teemo Attacking||56.5%|Easy||
|0495|Teemo Attacking|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0495.Teemo-Attacking)|56.5%|Easy||
|0496|Next Greater Element I|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0496.Next-Greater-Element-I)|68.7%|Easy||
|0497|Random Point in Non-overlapping Rectangles|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0497.Random-Point-in-Non-overlapping-Rectangles)|39.1%|Medium||
|0498|Diagonal Traverse|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0498.Diagonal-Traverse)|53.6%|Medium||
Expand Down Expand Up @@ -1396,7 +1396,7 @@
|1255|Maximum Score Words Formed by Letters||71.4%|Hard||
|1256|Encode Number||69.0%|Medium||
|1257|Smallest Common Region||62.0%|Medium||
|1258|Synonymous Sentences||57.5%|Medium||
|1258|Synonymous Sentences||57.4%|Medium||
|1259|Handshakes That Don't Cross||54.4%|Hard||
|1260|Shift 2D Grid|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1260.Shift-2D-Grid)|62.1%|Easy||
|1261|Find Elements in a Contaminated Binary Tree||75.4%|Medium||
Expand Down Expand Up @@ -1893,7 +1893,7 @@
|1752|Check if Array Is Sorted and Rotated|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated)|45.1%|Easy||
|1753|Maximum Score From Removing Stones||64.2%|Medium||
|1754|Largest Merge Of Two Strings||42.8%|Medium||
|1755|Closest Subsequence Sum||36.1%|Hard||
|1755|Closest Subsequence Sum||36.0%|Hard||
|1756|Design Most Recently Used Queue||77.8%|Medium||
|1757|Recyclable and Low Fat Products||95.8%|Easy||
|1758|Minimum Changes To Make Alternating Binary String|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1758.Minimum-Changes-To-Make-Alternating-Binary-String)|58.8%|Easy||
Expand Down Expand Up @@ -2206,15 +2206,15 @@
|2065|Maximum Path Quality of a Graph||56.1%|Hard||
|2066|Account Balance||84.5%|Medium||
|2067|Number of Equal Count Substrings||64.0%|Medium||
|2068|Check Whether Two Strings are Almost Equivalent||67.8%|Easy||
|2068|Check Whether Two Strings are Almost Equivalent||67.7%|Easy||
|2069|Walking Robot Simulation II||15.5%|Medium||
|2070|Most Beautiful Item for Each Query||42.6%|Medium||
|2070|Most Beautiful Item for Each Query||42.7%|Medium||
|2071|Maximum Number of Tasks You Can Assign||29.4%|Hard||
|2072|The Winner University||92.1%|Easy||
|2072|The Winner University||92.2%|Easy||
|2073|Time Needed to Buy Tickets||56.2%|Easy||
|2074|Reverse Nodes in Even Length Groups||38.7%|Medium||
|2075|Decode the Slanted Ciphertext||46.7%|Medium||
|2076|Process Restricted Friend Requests||38.5%|Hard||
|2074|Reverse Nodes in Even Length Groups||38.9%|Medium||
|2075|Decode the Slanted Ciphertext||46.9%|Medium||
|2076|Process Restricted Friend Requests||39.0%|Hard||
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|

------------------------------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions leetcode/0495.Teemo-Attacking/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [495. Teemo Attacking](https://leetcode-cn.com/problems/teemo-attacking/)
# [495. Teemo Attacking](https://leetcode.com/problems/teemo-attacking/)


## 题目
Expand Down Expand Up @@ -55,15 +55,16 @@ Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.

## 解题思路

- i从1开始计数,令t等于timeSeries[i - 1]
- 比较end(t + duration - 1)和timeSeries[i]的大小,
- 如果end小于timeSeries[i],ans+=duration
- 否则ans += timeSeries[i] - t
- ans += duration并返回ans
- i 从 1 开始计数,令 t 等于 timeSeries[i - 1]
- 比较 end(t + duration - 1) 和 timeSeries[i] 的大小,
- 如果 end 小于 timeSeries[i],ans+=duration
- 否则 ans += timeSeries[i] - t
- ans += duration 并返回 ans

## 代码

```go

package leetcode

func findPoisonedDuration(timeSeries []int, duration int) int {
Expand All @@ -80,4 +81,5 @@ func findPoisonedDuration(timeSeries []int, duration int) int {
ans += duration
return ans
}

```
2 changes: 1 addition & 1 deletion website/content/ChapterFour/0400~0499/0494.Target-Sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ func dfsFindTargetSumWays(nums []int, index int, curSum int, S int, res *int, su
----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0493.Reverse-Pairs/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0496.Next-Greater-Element-I/">下一页➡️</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0495.Teemo-Attacking/">下一页➡️</a></p>
</div>
92 changes: 92 additions & 0 deletions website/content/ChapterFour/0400~0499/0495.Teemo-Attacking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# [495. Teemo Attacking](https://leetcode.com/problems/teemo-attacking/)


## 题目

Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds.

More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1].

If Teemo attacks again before the poison effect ends, the timer for it is reset, and the poison effect will end duration seconds after the new attack.

You are given a non-decreasing integer array timeSeries, where timeSeries[i] denotes that Teemo attacks Ashe at second timeSeries[i], and an integer duration.

Return the total number of seconds that Ashe is poisoned.

**Example 1**:
```
Input: timeSeries = [1,4], duration = 2
Output: 4
Explanation: Teemo's attacks on Ashe go as follows:
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.
Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.
```

**Example 2**:
```
Input: timeSeries = [1,2], duration = 2
Output: 3
Explanation: Teemo's attacks on Ashe go as follows:
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.
Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.
```

**Constraints**:

- 1 <= timeSeries.length <= 10000
- 0 <= timeSeries[i], duration <= 10000000
- timeSeries is sorted in non-decreasing order.

## 题目大意

在《英雄联盟》的世界中,有一个叫 “提莫” 的英雄。他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。

当提莫攻击艾希,艾希的中毒状态正好持续duration 秒。

正式地讲,提莫在t发起发起攻击意味着艾希在时间区间 [t, t + duration - 1](含 t 和 t + duration - 1)处于中毒状态。

如果提莫在中毒影响结束前再次攻击,中毒状态计时器将会重置,在新的攻击之后,中毒影响将会在duration秒后结束。

给你一个非递减的整数数组timeSeries,其中timeSeries[i]表示提莫在timeSeries[i]秒时对艾希发起攻击,以及一个表示中毒持续时间的整数duration 。

返回艾希处于中毒状态的总秒数。

## 解题思路

- i 从 1 开始计数,令 t 等于 timeSeries[i - 1]
- 比较 end(t + duration - 1) 和 timeSeries[i] 的大小,
- 如果 end 小于 timeSeries[i],ans+=duration
- 否则 ans += timeSeries[i] - t
- ans += duration 并返回 ans

## 代码

```go

package leetcode

func findPoisonedDuration(timeSeries []int, duration int) int {
var ans int
for i := 1; i < len(timeSeries); i++ {
t := timeSeries[i-1]
end := t + duration - 1
if end < timeSeries[i] {
ans += duration
} else {
ans += timeSeries[i] - t
}
}
ans += duration
return ans
}

```


----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0494.Target-Sum/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0496.Next-Greater-Element-I/">下一页➡️</a></p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int {

----------------------------------------------
<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0494.Target-Sum/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0495.Teemo-Attacking/">⬅️上一页</a></p>
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0497.Random-Point-in-Non-overlapping-Rectangles/">下一页➡️</a></p>
</div>
7 changes: 4 additions & 3 deletions website/content/ChapterTwo/Array.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ weight: 1
|0491|Increasing Subsequences|[Go]({{< relref "/ChapterFour/0400~0499/0491.Increasing-Subsequences.md" >}})|Medium||||49.6%|
|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0400~0499/0493.Reverse-Pairs.md" >}})|Hard||||28.9%|
|0494|Target Sum|[Go]({{< relref "/ChapterFour/0400~0499/0494.Target-Sum.md" >}})|Medium||||45.3%|
|0495|Teemo Attacking|[Go]({{< relref "/ChapterFour/0400~0499/0495.Teemo-Attacking.md" >}})|Easy||||56.5%|
|0496|Next Greater Element I|[Go]({{< relref "/ChapterFour/0400~0499/0496.Next-Greater-Element-I.md" >}})|Easy||||68.7%|
|0498|Diagonal Traverse|[Go]({{< relref "/ChapterFour/0400~0499/0498.Diagonal-Traverse.md" >}})|Medium||||53.6%|
|0500|Keyboard Row|[Go]({{< relref "/ChapterFour/0500~0599/0500.Keyboard-Row.md" >}})|Easy||||67.1%|
Expand Down Expand Up @@ -268,7 +269,7 @@ weight: 1
|0990|Satisfiability of Equality Equations|[Go]({{< relref "/ChapterFour/0900~0999/0990.Satisfiability-of-Equality-Equations.md" >}})|Medium||||49.0%|
|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0900~0999/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard||||52.7%|
|0995|Minimum Number of K Consecutive Bit Flips|[Go]({{< relref "/ChapterFour/0900~0999/0995.Minimum-Number-of-K-Consecutive-Bit-Flips.md" >}})|Hard||||50.3%|
|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0900~0999/0996.Number-of-Squareful-Arrays.md" >}})|Hard||||49.1%|
|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0900~0999/0996.Number-of-Squareful-Arrays.md" >}})|Hard||||49.0%|
|0999|Available Captures for Rook|[Go]({{< relref "/ChapterFour/0900~0999/0999.Available-Captures-for-Rook.md" >}})|Easy||||67.6%|
|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1000~1099/1002.Find-Common-Characters.md" >}})|Easy||||68.5%|
|1004|Max Consecutive Ones III|[Go]({{< relref "/ChapterFour/1000~1099/1004.Max-Consecutive-Ones-III.md" >}})|Medium||||61.7%|
Expand Down Expand Up @@ -306,7 +307,7 @@ weight: 1
|1254|Number of Closed Islands|[Go]({{< relref "/ChapterFour/1200~1299/1254.Number-of-Closed-Islands.md" >}})|Medium||||62.7%|
|1260|Shift 2D Grid|[Go]({{< relref "/ChapterFour/1200~1299/1260.Shift-2D-Grid.md" >}})|Easy||||62.1%|
|1266|Minimum Time Visiting All Points|[Go]({{< relref "/ChapterFour/1200~1299/1266.Minimum-Time-Visiting-All-Points.md" >}})|Easy||||79.2%|
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.8%|
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.7%|
|1275|Find Winner on a Tic Tac Toe Game|[Go]({{< relref "/ChapterFour/1200~1299/1275.Find-Winner-on-a-Tic-Tac-Toe-Game.md" >}})|Easy||||55.7%|
|1283|Find the Smallest Divisor Given a Threshold|[Go]({{< relref "/ChapterFour/1200~1299/1283.Find-the-Smallest-Divisor-Given-a-Threshold.md" >}})|Medium||||52.2%|
|1287|Element Appearing More Than 25% In Sorted Array|[Go]({{< relref "/ChapterFour/1200~1299/1287.Element-Appearing-More-Than-25-In-Sorted-Array.md" >}})|Easy||||59.7%|
Expand Down Expand Up @@ -350,7 +351,7 @@ weight: 1
|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1600~1699/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||37.0%|
|1652|Defuse the Bomb|[Go]({{< relref "/ChapterFour/1600~1699/1652.Defuse-the-Bomb.md" >}})|Easy||||60.6%|
|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1600~1699/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||25.7%|
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.6%|
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.7%|
|1656|Design an Ordered Stream|[Go]({{< relref "/ChapterFour/1600~1699/1656.Design-an-Ordered-Stream.md" >}})|Easy||||82.6%|
|1658|Minimum Operations to Reduce X to Zero|[Go]({{< relref "/ChapterFour/1600~1699/1658.Minimum-Operations-to-Reduce-X-to-Zero.md" >}})|Medium||||33.3%|
|1662|Check If Two String Arrays are Equivalent|[Go]({{< relref "/ChapterFour/1600~1699/1662.Check-If-Two-String-Arrays-are-Equivalent.md" >}})|Easy||||82.0%|
Expand Down
2 changes: 1 addition & 1 deletion website/content/ChapterTwo/Stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ weight: 5
|0232|Implement Queue using Stacks|[Go]({{< relref "/ChapterFour/0200~0299/0232.Implement-Queue-using-Stacks.md" >}})|Easy| O(n)| O(n)||55.5%|
|0234|Palindrome Linked List|[Go]({{< relref "/ChapterFour/0200~0299/0234.Palindrome-Linked-List.md" >}})|Easy||||44.7%|
|0331|Verify Preorder Serialization of a Binary Tree|[Go]({{< relref "/ChapterFour/0300~0399/0331.Verify-Preorder-Serialization-of-a-Binary-Tree.md" >}})|Medium| O(n)| O(1)||43.4%|
|0341|Flatten Nested List Iterator|[Go]({{< relref "/ChapterFour/0300~0399/0341.Flatten-Nested-List-Iterator.md" >}})|Medium||||57.6%|
|0341|Flatten Nested List Iterator|[Go]({{< relref "/ChapterFour/0300~0399/0341.Flatten-Nested-List-Iterator.md" >}})|Medium||||57.5%|
|0385|Mini Parser|[Go]({{< relref "/ChapterFour/0300~0399/0385.Mini-Parser.md" >}})|Medium||||35.3%|
|0394|Decode String|[Go]({{< relref "/ChapterFour/0300~0399/0394.Decode-String.md" >}})|Medium| O(n)| O(n)||54.7%|
|0402|Remove K Digits|[Go]({{< relref "/ChapterFour/0400~0499/0402.Remove-K-Digits.md" >}})|Medium| O(n)| O(1)||29.0%|
Expand Down
2 changes: 1 addition & 1 deletion website/content/ChapterTwo/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ weight: 2
|1234|Replace the Substring for Balanced String|[Go]({{< relref "/ChapterFour/1200~1299/1234.Replace-the-Substring-for-Balanced-String.md" >}})|Medium||||35.5%|
|1239|Maximum Length of a Concatenated String with Unique Characters|[Go]({{< relref "/ChapterFour/1200~1299/1239.Maximum-Length-of-a-Concatenated-String-with-Unique-Characters.md" >}})|Medium||||50.6%|
|1249|Minimum Remove to Make Valid Parentheses|[Go]({{< relref "/ChapterFour/1200~1299/1249.Minimum-Remove-to-Make-Valid-Parentheses.md" >}})|Medium||||65.0%|
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.8%|
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.7%|
|1332|Remove Palindromic Subsequences|[Go]({{< relref "/ChapterFour/1300~1399/1332.Remove-Palindromic-Subsequences.md" >}})|Easy||||69.1%|
|1396|Design Underground System|[Go]({{< relref "/ChapterFour/1300~1399/1396.Design-Underground-System.md" >}})|Medium||||71.7%|
|1455|Check If a Word Occurs As a Prefix of Any Word in a Sentence|[Go]({{< relref "/ChapterFour/1400~1499/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence.md" >}})|Easy||||64.4%|
Expand Down

0 comments on commit d9a9759

Please sign in to comment.