Skip to content

Commit 545dd88

Browse files
author
Shuo
committed
Add: new
1 parent 23e5bc8 commit 545dd88

File tree

33 files changed

+808
-31
lines changed

33 files changed

+808
-31
lines changed

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65-
| <span id="1369">1369</span> | [Get the Second Most Recent Activity](https://leetcode.com/problems/get-the-second-most-recent-activity) 🔒 | [MySQL](problems/get-the-second-most-recent-activity) | Hard |
65+
| <span id="1377">1377</span> | [Frog Position After T Seconds](https://leetcode.com/problems/frog-position-after-t-seconds "T 秒后青蛙的位置") | [Go](problems/frog-position-after-t-seconds) | Hard |
66+
| <span id="1376">1376</span> | [Time Needed to Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees "通知所有员工所需的时间") | [Go](problems/time-needed-to-inform-all-employees) | Medium |
67+
| <span id="1375">1375</span> | [Bulb Switcher III](https://leetcode.com/problems/bulb-switcher-iii "灯泡开关 III") | [Go](problems/bulb-switcher-iii) | Medium |
68+
| <span id="1374">1374</span> | [Generate a String With Characters That Have Odd Counts](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts "生成每种字符都是奇数个的字符串") | [Go](problems/generate-a-string-with-characters-that-have-odd-counts) | Easy |
69+
| <span id="1373">1373</span> | [Maximum Sum BST in Binary Tree](https://leetcode.com/problems/maximum-sum-bst-in-binary-tree "二叉搜索子树的最大键值和") | [Go](problems/maximum-sum-bst-in-binary-tree) | Hard |
70+
| <span id="1372">1372</span> | [Longest ZigZag Path in a Binary Tree](https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree "二叉树中的最长交错路径") | [Go](problems/longest-zigzag-path-in-a-binary-tree) | Medium |
71+
| <span id="1371">1371</span> | [Find the Longest Substring Containing Vowels in Even Counts](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts "每个元音包含偶数次的最长子字符串") | [Go](problems/find-the-longest-substring-containing-vowels-in-even-counts) | Medium |
72+
| <span id="1370">1370</span> | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string "上升下降字符串") | [Go](problems/increasing-decreasing-string) | Easy |
73+
| <span id="1369">1369</span> | [Get the Second Most Recent Activity](https://leetcode.com/problems/get-the-second-most-recent-activity "获取最近第二次的活动") 🔒 | [MySQL](problems/get-the-second-most-recent-activity) | Hard |
6674
| <span id="1368">1368</span> | [Minimum Cost to Make at Least One Valid Path in a Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid "使网格图至少有一条有效路径的最小代价") | [Go](problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid) | Hard |
6775
| <span id="1367">1367</span> | [Linked List in Binary Tree](https://leetcode.com/problems/linked-list-in-binary-tree "二叉树中的列表") | [Go](problems/linked-list-in-binary-tree) | Medium |
6876
| <span id="1366">1366</span> | [Rank Teams by Votes](https://leetcode.com/problems/rank-teams-by-votes "通过投票对团队排名") | [Go](problems/rank-teams-by-votes) | Medium |
@@ -76,7 +84,7 @@ LeetCode Problems' Solutions
7684
| <span id="1358">1358</span> | [Number of Substrings Containing All Three Characters](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters "包含所有三种字符的子字符串数目") | [Go](problems/number-of-substrings-containing-all-three-characters) | Medium |
7785
| <span id="1357">1357</span> | [Apply Discount Every n Orders](https://leetcode.com/problems/apply-discount-every-n-orders "每隔 n 个顾客打折") | [Go](problems/apply-discount-every-n-orders) | Medium |
7886
| <span id="1356">1356</span> | [Sort Integers by The Number of 1 Bits](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits "根据数字二进制下 1 的数目排序") | [Go](problems/sort-integers-by-the-number-of-1-bits) | Easy |
79-
| <span id="1355">1355</span> | [Activity Participants](https://leetcode.com/problems/activity-participants) 🔒 | [MySQL](problems/activity-participants) | Medium |
87+
| <span id="1355">1355</span> | [Activity Participants](https://leetcode.com/problems/activity-participants "活动参与者") 🔒 | [MySQL](problems/activity-participants) | Medium |
8088
| <span id="1354">1354</span> | [Construct Target Array With Multiple Sums](https://leetcode.com/problems/construct-target-array-with-multiple-sums "多次求和构造目标数组") | [Go](problems/construct-target-array-with-multiple-sums) | Hard |
8189
| <span id="1353">1353</span> | [Maximum Number of Events That Can Be Attended](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended "最多可以参加的会议数目") | [Go](problems/maximum-number-of-events-that-can-be-attended) | Medium |
8290
| <span id="1352">1352</span> | [Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers "最后 K 个数的乘积") | [Go](problems/product-of-the-last-k-numbers) | Medium |

problems/activity-participants/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../sort-integers-by-the-number-of-1-bits "Sort Integers by The Number of 1 Bits")
1111

12-
## [1355. Activity Participants (Medium)](https://leetcode.com/problems/activity-participants "")
12+
## [1355. Activity Participants (Medium)](https://leetcode.com/problems/activity-participants "活动参与者")
1313

1414
<p>Table: <code>Friends</code></p>
1515
<pre>

problems/bulb-switcher-iii/README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../generate-a-string-with-characters-that-have-odd-counts "Generate a String With Characters That Have Odd Counts")
9+
                
10+
[Next >](../time-needed-to-inform-all-employees "Time Needed to Inform All Employees")
11+
12+
## [1375. Bulb Switcher III (Medium)](https://leetcode.com/problems/bulb-switcher-iii "灯泡开关 III")
13+
14+
<p>There is a room with <code>n</code> bulbs, numbered from <code>1</code> to <code>n</code>, arranged in a row from left to right. Initially, all the bulbs are turned off.</p>
15+
16+
<p>At moment <em>k</em> (for <em>k</em> from <code>0</code> to <code>n - 1</code>), we turn on the <code>light[k]</code> bulb. A bulb <strong>change&nbsp;color to blue</strong> only if it is on and all the previous bulbs (to the left)&nbsp;are turned on too.</p>
17+
18+
<p>Return the number of moments in&nbsp;which <strong>all&nbsp;turned on</strong> bulbs&nbsp;<strong>are blue.</strong></p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/02/29/sample_2_1725.png" style="width: 575px; height: 300px;" /></p>
24+
25+
<pre>
26+
<strong>Input:</strong> light = [2,1,3,5,4]
27+
<strong>Output:</strong> 3
28+
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 1, 2 and 4.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> light = [3,2,4,1,5]
35+
<strong>Output:</strong> 2
36+
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 3, and 4 (index-0).
37+
</pre>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> light = [4,1,2,3]
43+
<strong>Output:</strong> 1
44+
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 3 (index-0).
45+
Bulb 4th changes to blue at the moment 3.
46+
</pre>
47+
48+
<p><strong>Example 4:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong> light = [2,1,4,3,6,5]
52+
<strong>Output:</strong> 3
53+
</pre>
54+
55+
<p><strong>Example 5:</strong></p>
56+
57+
<pre>
58+
<strong>Input:</strong> light = [1,2,3,4,5,6]
59+
<strong>Output:</strong> 6
60+
</pre>
61+
62+
<p>&nbsp;</p>
63+
<p><strong>Constraints:</strong></p>
64+
65+
<ul>
66+
<li><code>n ==&nbsp;light.length</code></li>
67+
<li><code>1 &lt;= n &lt;= 5 * 10^4</code></li>
68+
<li><code>light</code> is a permutation of&nbsp;&nbsp;<code>[1, 2, ..., n]</code></li>
69+
</ul>
70+
71+
### Related Topics
72+
[[Array](../../tag/array/README.md)]
73+
74+
### Hints
75+
<details>
76+
<summary>Hint 1</summary>
77+
If in the step x all bulb shines then bulbs 1,2,3,..,x should shines too.
78+
</details>

problems/complement-of-base-10-integer/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
<ol>
5757
<li><code>0 &lt;= N &lt; 10^9</code></li>
58+
<li>This question is the same as 476:&nbsp;<a href="https://leetcode.com/problems/number-complement/">https://leetcode.com/problems/number-complement/</a></li>
5859
</ol>
5960
</div>
6061
</div>

problems/count-unique-characters-of-all-substrings-of-a-given-string/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../consecutive-numbers-sum "Consecutive Numbers Sum")
1111

12-
## [828. Count Unique Characters of All Substrings of a Given String (Hard)](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string "独特字符串")
12+
## [828. Count Unique Characters of All Substrings of a Given String (Hard)](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string "统计子串中的唯一字符")
1313

1414
<p>Let&#39;s define a function <code>countUniqueChars(s)</code>&nbsp;that returns the number of unique characters on <code>s</code>, for example if <code>s = &quot;LEETCODE&quot;</code>&nbsp;then <code>&quot;L&quot;</code>, <code>&quot;T&quot;</code>,<code>&quot;C&quot;</code>,<code>&quot;O&quot;</code>,<code>&quot;D&quot;</code> are the unique characters since they appear only once in <code>s</code>, therefore&nbsp;<code>countUniqueChars(s) = 5</code>.<br />
1515
<br />

problems/decompress-run-length-encoded-list/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<p>We are given a list <code>nums</code> of integers representing a list compressed with run-length encoding.</p>
1515

16-
<p>Consider each adjacent pair&nbsp;of elements <code>[a, b] = [nums[2*i], nums[2*i+1]]</code>&nbsp;(with <code>i &gt;= 0</code>).&nbsp; For each such pair, there are <code>a</code> elements with value <code>b</code> in the decompressed list.</p>
16+
<p>Consider each adjacent pair&nbsp;of elements <code>[freq, val] = [nums[2*i], nums[2*i+1]]</code>&nbsp;(with <code>i &gt;= 0</code>).&nbsp; For each such pair, there are <code>freq</code> elements with value <code>val</code> concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.</p>
1717

1818
<p>Return the decompressed list.</p>
1919

@@ -28,6 +28,13 @@ The second pair [3,4] means we have freq = 3 and val = 4 so we generate [4,4,4].
2828
At the end the concatenation [2] + [4,4,4] is [2,4,4,4].
2929
</pre>
3030

31+
<p><strong>Example 2:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> nums = [1,1,2,3]
35+
<strong>Output:</strong> [1,3,3]
36+
</pre>
37+
3138
<p>&nbsp;</p>
3239
<p><strong>Constraints:</strong></p>
3340

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../increasing-decreasing-string "Increasing Decreasing String")
9+
                
10+
[Next >](../longest-zigzag-path-in-a-binary-tree "Longest ZigZag Path in a Binary Tree")
11+
12+
## [1371. Find the Longest Substring Containing Vowels in Even Counts (Medium)](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts "每个元音包含偶数次的最长子字符串")
13+
14+
<p>Given the string <code>s</code>, return the size of the longest substring containing each vowel an even number of times. That is, &#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, and &#39;u&#39; must appear an even number of times.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
<strong>Input:</strong> s = &quot;eleetminicoworoep&quot;
21+
<strong>Output:</strong> 13
22+
<strong>Explanation: </strong>The longest substring is &quot;leetminicowor&quot; which contains two each of the vowels: <strong>e</strong>, <strong>i</strong> and <strong>o</strong> and zero of the vowels: <strong>a</strong> and <strong>u</strong>.
23+
</pre>
24+
25+
<p><strong>Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> s = &quot;leetcodeisgreat&quot;
29+
<strong>Output:</strong> 5
30+
<strong>Explanation:</strong> The longest substring is &quot;leetc&quot; which contains two e&#39;s.
31+
</pre>
32+
33+
<p><strong>Example 3:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> s = &quot;bcbcbc&quot;
37+
<strong>Output:</strong> 6
38+
<strong>Explanation:</strong> In this case, the given string &quot;bcbcbc&quot; is the longest because all vowels: <strong>a</strong>, <strong>e</strong>, <strong>i</strong>, <strong>o</strong> and <strong>u</strong> appear zero times.
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= s.length &lt;= 5 x 10^5</code></li>
46+
<li><code>s</code>&nbsp;contains only lowercase English letters.</li>
47+
</ul>
48+
49+
### Related Topics
50+
[[String](../../tag/string/README.md)]
51+
52+
### Hints
53+
<details>
54+
<summary>Hint 1</summary>
55+
Represent the counts (odd or even) of vowels with a bitmask.
56+
</details>
57+
58+
<details>
59+
<summary>Hint 2</summary>
60+
Precompute the prefix xor for the bitmask of vowels and then get the longest valid substring.
61+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../time-needed-to-inform-all-employees "Time Needed to Inform All Employees")
9+
                
10+
Next >
11+
12+
## [1377. Frog Position After T Seconds (Hard)](https://leetcode.com/problems/frog-position-after-t-seconds "T 秒后青蛙的位置")
13+
14+
<p>Given an undirected tree&nbsp;consisting of <code>n</code> vertices numbered from 1 to <code>n</code>. A frog starts jumping&nbsp;from the <strong>vertex 1</strong>. In one second, the frog&nbsp;jumps from its&nbsp;current&nbsp;vertex to another <strong>unvisited</strong> vertex if they are directly connected. The frog can not jump back to a visited vertex.&nbsp;In case the frog can jump to several vertices it jumps randomly to one of them with the same probability, otherwise, when the frog can not jump to any unvisited vertex it jumps forever on the same vertex.&nbsp;</p>
15+
16+
<p>The edges of the undirected tree&nbsp;are given in the array <code>edges</code>, where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> means that exists an edge connecting directly the vertices <code>from<sub>i</sub></code> and <code>to<sub>i</sub></code>.</p>
17+
18+
<p><em>Return the probability that after <code>t</code> seconds the frog is on the vertex <code><font face="monospace">target</font></code>.</em></p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/frog_2.png" style="width: 350px; height: 236px;" /></p>
24+
25+
<pre>
26+
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4
27+
<strong>Output:</strong> 0.16666666666666666
28+
<strong>Explanation: </strong>The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 probability to the vertex 2 after <strong>second 1</strong> and then jumping with 1/2 probability to vertex 4 after <strong>second 2</strong>. Thus the probability for the frog is on the vertex 4 after 2 seconds is 1/3 * 1/2 = 1/6 = 0.16666666666666666.
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
33+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/frog_3.png" style="width: 350px; height: 236px;" /></strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7
37+
<strong>Output:</strong> 0.3333333333333333
38+
<strong>Explanation: </strong>The figure above shows the given graph. The frog starts at vertex 1, jumping with 1/3 = 0.3333333333333333 probability to the vertex 7 after <strong>second 1</strong>.
39+
</pre>
40+
41+
<p><strong>Example 3:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6
45+
<strong>Output:</strong> 0.16666666666666666
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= n &lt;= 100</code></li>
53+
<li><code>edges.length == n-1</code></li>
54+
<li><code>edges[i].length == 2</code></li>
55+
<li><code>1 &lt;= edges[i][0], edges[i][1] &lt;= n</code></li>
56+
<li><code>1 &lt;= t&nbsp;&lt;= 50</code></li>
57+
<li><code>1 &lt;= target&nbsp;&lt;= n</code></li>
58+
<li>Answers within <code>10^-5</code> of the actual value will be accepted as correct.</li>
59+
</ul>
60+
61+
### Related Topics
62+
[[Depth-first Search](../../tag/depth-first-search/README.md)]
63+
64+
### Hints
65+
<details>
66+
<summary>Hint 1</summary>
67+
Use a variation of DFS with parameters 'curent_vertex' and 'current_time'.
68+
</details>
69+
70+
<details>
71+
<summary>Hint 2</summary>
72+
Update the probability considering to jump to one of the children vertices.
73+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../maximum-sum-bst-in-binary-tree "Maximum Sum BST in Binary Tree")
9+
                
10+
[Next >](../bulb-switcher-iii "Bulb Switcher III")
11+
12+
## [1374. Generate a String With Characters That Have Odd Counts (Easy)](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts "生成每种字符都是奇数个的字符串")
13+
14+
<p>Given an&nbsp;integer <code>n</code>, <em>return a string with <code>n</code>&nbsp;characters such that each character in such string occurs <strong>an odd number of times</strong></em>.</p>
15+
16+
<p>The returned string must contain only lowercase English letters. If there are multiples valid strings, return <strong>any</strong> of them. &nbsp;</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> n = 4
23+
<strong>Output:</strong> &quot;pppz&quot;
24+
<strong>Explanation:</strong> &quot;pppz&quot; is a valid string since the character &#39;p&#39; occurs three times and the character &#39;z&#39; occurs once. Note that there are many other valid strings such as &quot;ohhh&quot; and &quot;love&quot;.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> n = 2
31+
<strong>Output:</strong> &quot;xy&quot;
32+
<strong>Explanation:</strong> &quot;xy&quot; is a valid string since the characters &#39;x&#39; and &#39;y&#39; occur once. Note that there are many other valid strings such as &quot;ag&quot; and &quot;ur&quot;.
33+
</pre>
34+
35+
<p><strong>Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> n = 7
39+
<strong>Output:</strong> &quot;holasss&quot;
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= n &lt;= 500</code></li>
47+
</ul>
48+
49+
### Related Topics
50+
[[String](../../tag/string/README.md)]
51+
52+
### Hints
53+
<details>
54+
<summary>Hint 1</summary>
55+
If n is odd, return a string of size n formed only by 'a', else return string formed with n-1 'a' and 1 'b''.
56+
</details>

0 commit comments

Comments
 (0)