Skip to content

Commit d9a9759

Browse files
halfrostdezhiy
authored andcommitted
Add solution 0494
1 parent 3024684 commit d9a9759

File tree

8 files changed

+120
-25
lines changed

8 files changed

+120
-25
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@
127127
| | Easy | Medium | Hard | Total |
128128
|:--------:|:--------:|:--------:|:--------:|:--------:|
129129
|Optimizing|33|45|30|108|
130-
|Accepted|**279**|**426**|**126**|**831**|
130+
|Accepted|**280**|**426**|**126**|**832**|
131131
|Total|527|1107|442|2076|
132132
|Perfection Rate|88.2%|89.4%|76.2%|87.0%|
133-
|Completion Rate|52.9%|38.5%|28.5%|40.0%|
133+
|Completion Rate|53.1%|38.5%|28.5%|40.1%|
134134
|------------|----------------------------|----------------------------|----------------------------|----------------------------|
135135

136136
## 二. 目录
137137

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

140140
| No. | Title | Solution | Acceptance | Difficulty | Frequency |
141141
|:--------:|:--------------------------------------------------------------|:--------:|:--------:|:--------:|:--------:|
@@ -633,7 +633,7 @@
633633
|0492|Construct the Rectangle|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0492.Construct-the-Rectangle)|51.8%|Easy||
634634
|0493|Reverse Pairs|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0493.Reverse-Pairs)|28.9%|Hard||
635635
|0494|Target Sum|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0494.Target-Sum)|45.3%|Medium||
636-
|0495|Teemo Attacking||56.5%|Easy||
636+
|0495|Teemo Attacking|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0495.Teemo-Attacking)|56.5%|Easy||
637637
|0496|Next Greater Element I|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0496.Next-Greater-Element-I)|68.7%|Easy||
638638
|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||
639639
|0498|Diagonal Traverse|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/0498.Diagonal-Traverse)|53.6%|Medium||
@@ -1396,7 +1396,7 @@
13961396
|1255|Maximum Score Words Formed by Letters||71.4%|Hard||
13971397
|1256|Encode Number||69.0%|Medium||
13981398
|1257|Smallest Common Region||62.0%|Medium||
1399-
|1258|Synonymous Sentences||57.5%|Medium||
1399+
|1258|Synonymous Sentences||57.4%|Medium||
14001400
|1259|Handshakes That Don't Cross||54.4%|Hard||
14011401
|1260|Shift 2D Grid|[Go](https://github.com/halfrost/LeetCode-Go/tree/master/leetcode/1260.Shift-2D-Grid)|62.1%|Easy||
14021402
|1261|Find Elements in a Contaminated Binary Tree||75.4%|Medium||
@@ -1893,7 +1893,7 @@
18931893
|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||
18941894
|1753|Maximum Score From Removing Stones||64.2%|Medium||
18951895
|1754|Largest Merge Of Two Strings||42.8%|Medium||
1896-
|1755|Closest Subsequence Sum||36.1%|Hard||
1896+
|1755|Closest Subsequence Sum||36.0%|Hard||
18971897
|1756|Design Most Recently Used Queue||77.8%|Medium||
18981898
|1757|Recyclable and Low Fat Products||95.8%|Easy||
18991899
|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||
@@ -2206,15 +2206,15 @@
22062206
|2065|Maximum Path Quality of a Graph||56.1%|Hard||
22072207
|2066|Account Balance||84.5%|Medium||
22082208
|2067|Number of Equal Count Substrings||64.0%|Medium||
2209-
|2068|Check Whether Two Strings are Almost Equivalent||67.8%|Easy||
2209+
|2068|Check Whether Two Strings are Almost Equivalent||67.7%|Easy||
22102210
|2069|Walking Robot Simulation II||15.5%|Medium||
2211-
|2070|Most Beautiful Item for Each Query||42.6%|Medium||
2211+
|2070|Most Beautiful Item for Each Query||42.7%|Medium||
22122212
|2071|Maximum Number of Tasks You Can Assign||29.4%|Hard||
2213-
|2072|The Winner University||92.1%|Easy||
2213+
|2072|The Winner University||92.2%|Easy||
22142214
|2073|Time Needed to Buy Tickets||56.2%|Easy||
2215-
|2074|Reverse Nodes in Even Length Groups||38.7%|Medium||
2216-
|2075|Decode the Slanted Ciphertext||46.7%|Medium||
2217-
|2076|Process Restricted Friend Requests||38.5%|Hard||
2215+
|2074|Reverse Nodes in Even Length Groups||38.9%|Medium||
2216+
|2075|Decode the Slanted Ciphertext||46.9%|Medium||
2217+
|2076|Process Restricted Friend Requests||39.0%|Hard||
22182218
|------------|-------------------------------------------------------|-------| ----------------| ---------------|-------------|
22192219

22202220
------------------------------------------------------------------

leetcode/0495.Teemo-Attacking/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [495. Teemo Attacking](https://leetcode-cn.com/problems/teemo-attacking/)
1+
# [495. Teemo Attacking](https://leetcode.com/problems/teemo-attacking/)
22

33

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

5656
## 解题思路
5757

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

6464
## 代码
6565

6666
```go
67+
6768
package leetcode
6869

6970
func findPoisonedDuration(timeSeries []int, duration int) int {
@@ -80,4 +81,5 @@ func findPoisonedDuration(timeSeries []int, duration int) int {
8081
ans += duration
8182
return ans
8283
}
84+
8385
```

website/content/ChapterFour/0400~0499/0494.Target-Sum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ func dfsFindTargetSumWays(nums []int, index int, curSum int, S int, res *int, su
111111
----------------------------------------------
112112
<div style="display: flex;justify-content: space-between;align-items: center;">
113113
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0493.Reverse-Pairs/">⬅️上一页</a></p>
114-
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0496.Next-Greater-Element-I/">下一页➡️</a></p>
114+
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0495.Teemo-Attacking/">下一页➡️</a></p>
115115
</div>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [495. Teemo Attacking](https://leetcode.com/problems/teemo-attacking/)
2+
3+
4+
## 题目
5+
6+
Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds.
7+
8+
More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval [t, t + duration - 1].
9+
10+
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.
11+
12+
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.
13+
14+
Return the total number of seconds that Ashe is poisoned.
15+
16+
**Example 1**:
17+
```
18+
Input: timeSeries = [1,4], duration = 2
19+
Output: 4
20+
Explanation: Teemo's attacks on Ashe go as follows:
21+
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
22+
- At second 4, Teemo attacks, and Ashe is poisoned for seconds 4 and 5.
23+
Ashe is poisoned for seconds 1, 2, 4, and 5, which is 4 seconds in total.
24+
```
25+
26+
**Example 2**:
27+
```
28+
Input: timeSeries = [1,2], duration = 2
29+
Output: 3
30+
Explanation: Teemo's attacks on Ashe go as follows:
31+
- At second 1, Teemo attacks, and Ashe is poisoned for seconds 1 and 2.
32+
- At second 2 however, Teemo attacks again and resets the poison timer. Ashe is poisoned for seconds 2 and 3.
33+
Ashe is poisoned for seconds 1, 2, and 3, which is 3 seconds in total.
34+
```
35+
36+
**Constraints**:
37+
38+
- 1 <= timeSeries.length <= 10000
39+
- 0 <= timeSeries[i], duration <= 10000000
40+
- timeSeries is sorted in non-decreasing order.
41+
42+
## 题目大意
43+
44+
在《英雄联盟》的世界中,有一个叫 “提莫” 的英雄。他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。
45+
46+
当提莫攻击艾希,艾希的中毒状态正好持续duration 秒。
47+
48+
正式地讲,提莫在t发起发起攻击意味着艾希在时间区间 [t, t + duration - 1](含 t 和 t + duration - 1)处于中毒状态。
49+
50+
如果提莫在中毒影响结束前再次攻击,中毒状态计时器将会重置,在新的攻击之后,中毒影响将会在duration秒后结束。
51+
52+
给你一个非递减的整数数组timeSeries,其中timeSeries[i]表示提莫在timeSeries[i]秒时对艾希发起攻击,以及一个表示中毒持续时间的整数duration 。
53+
54+
返回艾希处于中毒状态的总秒数。
55+
56+
## 解题思路
57+
58+
- i 从 1 开始计数,令 t 等于 timeSeries[i - 1]
59+
- 比较 end(t + duration - 1) 和 timeSeries[i] 的大小,
60+
- 如果 end 小于 timeSeries[i],ans+=duration
61+
- 否则 ans += timeSeries[i] - t
62+
- ans += duration 并返回 ans
63+
64+
## 代码
65+
66+
```go
67+
68+
package leetcode
69+
70+
func findPoisonedDuration(timeSeries []int, duration int) int {
71+
var ans int
72+
for i := 1; i < len(timeSeries); i++ {
73+
t := timeSeries[i-1]
74+
end := t + duration - 1
75+
if end < timeSeries[i] {
76+
ans += duration
77+
} else {
78+
ans += timeSeries[i] - t
79+
}
80+
}
81+
ans += duration
82+
return ans
83+
}
84+
85+
```
86+
87+
88+
----------------------------------------------
89+
<div style="display: flex;justify-content: space-between;align-items: center;">
90+
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0494.Target-Sum/">⬅️上一页</a></p>
91+
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0496.Next-Greater-Element-I/">下一页➡️</a></p>
92+
</div>

website/content/ChapterFour/0400~0499/0496.Next-Greater-Element-I.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ func nextGreaterElement(nums1 []int, nums2 []int) []int {
8282

8383
----------------------------------------------
8484
<div style="display: flex;justify-content: space-between;align-items: center;">
85-
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0494.Target-Sum/">⬅️上一页</a></p>
85+
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0495.Teemo-Attacking/">⬅️上一页</a></p>
8686
<p><a href="https://books.halfrost.com/leetcode/ChapterFour/0400~0499/0497.Random-Point-in-Non-overlapping-Rectangles/">下一页➡️</a></p>
8787
</div>

website/content/ChapterTwo/Array.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ weight: 1
144144
|0491|Increasing Subsequences|[Go]({{< relref "/ChapterFour/0400~0499/0491.Increasing-Subsequences.md" >}})|Medium||||49.6%|
145145
|0493|Reverse Pairs|[Go]({{< relref "/ChapterFour/0400~0499/0493.Reverse-Pairs.md" >}})|Hard||||28.9%|
146146
|0494|Target Sum|[Go]({{< relref "/ChapterFour/0400~0499/0494.Target-Sum.md" >}})|Medium||||45.3%|
147+
|0495|Teemo Attacking|[Go]({{< relref "/ChapterFour/0400~0499/0495.Teemo-Attacking.md" >}})|Easy||||56.5%|
147148
|0496|Next Greater Element I|[Go]({{< relref "/ChapterFour/0400~0499/0496.Next-Greater-Element-I.md" >}})|Easy||||68.7%|
148149
|0498|Diagonal Traverse|[Go]({{< relref "/ChapterFour/0400~0499/0498.Diagonal-Traverse.md" >}})|Medium||||53.6%|
149150
|0500|Keyboard Row|[Go]({{< relref "/ChapterFour/0500~0599/0500.Keyboard-Row.md" >}})|Easy||||67.1%|
@@ -268,7 +269,7 @@ weight: 1
268269
|0990|Satisfiability of Equality Equations|[Go]({{< relref "/ChapterFour/0900~0999/0990.Satisfiability-of-Equality-Equations.md" >}})|Medium||||49.0%|
269270
|0992|Subarrays with K Different Integers|[Go]({{< relref "/ChapterFour/0900~0999/0992.Subarrays-with-K-Different-Integers.md" >}})|Hard||||52.7%|
270271
|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%|
271-
|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0900~0999/0996.Number-of-Squareful-Arrays.md" >}})|Hard||||49.1%|
272+
|0996|Number of Squareful Arrays|[Go]({{< relref "/ChapterFour/0900~0999/0996.Number-of-Squareful-Arrays.md" >}})|Hard||||49.0%|
272273
|0999|Available Captures for Rook|[Go]({{< relref "/ChapterFour/0900~0999/0999.Available-Captures-for-Rook.md" >}})|Easy||||67.6%|
273274
|1002|Find Common Characters|[Go]({{< relref "/ChapterFour/1000~1099/1002.Find-Common-Characters.md" >}})|Easy||||68.5%|
274275
|1004|Max Consecutive Ones III|[Go]({{< relref "/ChapterFour/1000~1099/1004.Max-Consecutive-Ones-III.md" >}})|Medium||||61.7%|
@@ -306,7 +307,7 @@ weight: 1
306307
|1254|Number of Closed Islands|[Go]({{< relref "/ChapterFour/1200~1299/1254.Number-of-Closed-Islands.md" >}})|Medium||||62.7%|
307308
|1260|Shift 2D Grid|[Go]({{< relref "/ChapterFour/1200~1299/1260.Shift-2D-Grid.md" >}})|Easy||||62.1%|
308309
|1266|Minimum Time Visiting All Points|[Go]({{< relref "/ChapterFour/1200~1299/1266.Minimum-Time-Visiting-All-Points.md" >}})|Easy||||79.2%|
309-
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.8%|
310+
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.7%|
310311
|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%|
311312
|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%|
312313
|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%|
@@ -350,7 +351,7 @@ weight: 1
350351
|1649|Create Sorted Array through Instructions|[Go]({{< relref "/ChapterFour/1600~1699/1649.Create-Sorted-Array-through-Instructions.md" >}})|Hard||||37.0%|
351352
|1652|Defuse the Bomb|[Go]({{< relref "/ChapterFour/1600~1699/1652.Defuse-the-Bomb.md" >}})|Easy||||60.6%|
352353
|1654|Minimum Jumps to Reach Home|[Go]({{< relref "/ChapterFour/1600~1699/1654.Minimum-Jumps-to-Reach-Home.md" >}})|Medium||||25.7%|
353-
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.6%|
354+
|1655|Distribute Repeating Integers|[Go]({{< relref "/ChapterFour/1600~1699/1655.Distribute-Repeating-Integers.md" >}})|Hard||||40.7%|
354355
|1656|Design an Ordered Stream|[Go]({{< relref "/ChapterFour/1600~1699/1656.Design-an-Ordered-Stream.md" >}})|Easy||||82.6%|
355356
|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%|
356357
|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%|

website/content/ChapterTwo/Stack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ weight: 5
3636
|0232|Implement Queue using Stacks|[Go]({{< relref "/ChapterFour/0200~0299/0232.Implement-Queue-using-Stacks.md" >}})|Easy| O(n)| O(n)||55.5%|
3737
|0234|Palindrome Linked List|[Go]({{< relref "/ChapterFour/0200~0299/0234.Palindrome-Linked-List.md" >}})|Easy||||44.7%|
3838
|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%|
39-
|0341|Flatten Nested List Iterator|[Go]({{< relref "/ChapterFour/0300~0399/0341.Flatten-Nested-List-Iterator.md" >}})|Medium||||57.6%|
39+
|0341|Flatten Nested List Iterator|[Go]({{< relref "/ChapterFour/0300~0399/0341.Flatten-Nested-List-Iterator.md" >}})|Medium||||57.5%|
4040
|0385|Mini Parser|[Go]({{< relref "/ChapterFour/0300~0399/0385.Mini-Parser.md" >}})|Medium||||35.3%|
4141
|0394|Decode String|[Go]({{< relref "/ChapterFour/0300~0399/0394.Decode-String.md" >}})|Medium| O(n)| O(n)||54.7%|
4242
|0402|Remove K Digits|[Go]({{< relref "/ChapterFour/0400~0499/0402.Remove-K-Digits.md" >}})|Medium| O(n)| O(1)||29.0%|

website/content/ChapterTwo/String.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ weight: 2
154154
|1234|Replace the Substring for Balanced String|[Go]({{< relref "/ChapterFour/1200~1299/1234.Replace-the-Substring-for-Balanced-String.md" >}})|Medium||||35.5%|
155155
|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%|
156156
|1249|Minimum Remove to Make Valid Parentheses|[Go]({{< relref "/ChapterFour/1200~1299/1249.Minimum-Remove-to-Make-Valid-Parentheses.md" >}})|Medium||||65.0%|
157-
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.8%|
157+
|1268|Search Suggestions System|[Go]({{< relref "/ChapterFour/1200~1299/1268.Search-Suggestions-System.md" >}})|Medium||||65.7%|
158158
|1332|Remove Palindromic Subsequences|[Go]({{< relref "/ChapterFour/1300~1399/1332.Remove-Palindromic-Subsequences.md" >}})|Easy||||69.1%|
159159
|1396|Design Underground System|[Go]({{< relref "/ChapterFour/1300~1399/1396.Design-Underground-System.md" >}})|Medium||||71.7%|
160160
|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%|

0 commit comments

Comments
 (0)