-
Notifications
You must be signed in to change notification settings - Fork 130
Add: new #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add: new #768
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
problems/bulb-switcher-iii/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../generate-a-string-with-characters-that-have-odd-counts "Generate a String With Characters That Have Odd Counts") | ||
|
||
[Next >](../time-needed-to-inform-all-employees "Time Needed to Inform All Employees") | ||
|
||
## [1375. Bulb Switcher III (Medium)](https://leetcode.com/problems/bulb-switcher-iii "灯泡开关 III") | ||
|
||
<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> | ||
|
||
<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 color to blue</strong> only if it is on and all the previous bulbs (to the left) are turned on too.</p> | ||
|
||
<p>Return the number of moments in which <strong>all turned on</strong> bulbs <strong>are blue.</strong></p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/02/29/sample_2_1725.png" style="width: 575px; height: 300px;" /></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> light = [2,1,3,5,4] | ||
<strong>Output:</strong> 3 | ||
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 1, 2 and 4. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> light = [3,2,4,1,5] | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 3, and 4 (index-0). | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> light = [4,1,2,3] | ||
<strong>Output:</strong> 1 | ||
<strong>Explanation:</strong> All bulbs turned on, are blue at the moment 3 (index-0). | ||
Bulb 4th changes to blue at the moment 3. | ||
</pre> | ||
|
||
<p><strong>Example 4:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> light = [2,1,4,3,6,5] | ||
<strong>Output:</strong> 3 | ||
</pre> | ||
|
||
<p><strong>Example 5:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> light = [1,2,3,4,5,6] | ||
<strong>Output:</strong> 6 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>n == light.length</code></li> | ||
<li><code>1 <= n <= 5 * 10^4</code></li> | ||
<li><code>light</code> is a permutation of <code>[1, 2, ..., n]</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Array](../../tag/array/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
If in the step x all bulb shines then bulbs 1,2,3,..,x should shines too. | ||
</details> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
problems/find-the-longest-substring-containing-vowels-in-even-counts/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../increasing-decreasing-string "Increasing Decreasing String") | ||
|
||
[Next >](../longest-zigzag-path-in-a-binary-tree "Longest ZigZag Path in a Binary Tree") | ||
|
||
## [1371. Find the Longest Substring Containing Vowels in Even Counts (Medium)](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts "每个元音包含偶数次的最长子字符串") | ||
|
||
<p>Given the string <code>s</code>, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "eleetminicoworoep" | ||
<strong>Output:</strong> 13 | ||
<strong>Explanation: </strong>The longest substring is "leetminicowor" 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>. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "leetcodeisgreat" | ||
<strong>Output:</strong> 5 | ||
<strong>Explanation:</strong> The longest substring is "leetc" which contains two e's. | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> s = "bcbcbc" | ||
<strong>Output:</strong> 6 | ||
<strong>Explanation:</strong> In this case, the given string "bcbcbc" 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. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= s.length <= 5 x 10^5</code></li> | ||
<li><code>s</code> contains only lowercase English letters.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[String](../../tag/string/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Represent the counts (odd or even) of vowels with a bitmask. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Precompute the prefix xor for the bitmask of vowels and then get the longest valid substring. | ||
</details> |
73 changes: 73 additions & 0 deletions
problems/frog-position-after-t-seconds/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../time-needed-to-inform-all-employees "Time Needed to Inform All Employees") | ||
|
||
Next > | ||
|
||
## [1377. Frog Position After T Seconds (Hard)](https://leetcode.com/problems/frog-position-after-t-seconds "T 秒后青蛙的位置") | ||
|
||
<p>Given an undirected tree consisting of <code>n</code> vertices numbered from 1 to <code>n</code>. A frog starts jumping from the <strong>vertex 1</strong>. In one second, the frog jumps from its current vertex to another <strong>unvisited</strong> vertex if they are directly connected. The frog can not jump back to a visited vertex. 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. </p> | ||
|
||
<p>The edges of the undirected tree 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> | ||
|
||
<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> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/frog_2.png" style="width: 350px; height: 236px;" /></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4 | ||
<strong>Output:</strong> 0.16666666666666666 | ||
<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. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/frog_3.png" style="width: 350px; height: 236px;" /></strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7 | ||
<strong>Output:</strong> 0.3333333333333333 | ||
<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>. | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 20, target = 6 | ||
<strong>Output:</strong> 0.16666666666666666 | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= n <= 100</code></li> | ||
<li><code>edges.length == n-1</code></li> | ||
<li><code>edges[i].length == 2</code></li> | ||
<li><code>1 <= edges[i][0], edges[i][1] <= n</code></li> | ||
<li><code>1 <= t <= 50</code></li> | ||
<li><code>1 <= target <= n</code></li> | ||
<li>Answers within <code>10^-5</code> of the actual value will be accepted as correct.</li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[Depth-first Search](../../tag/depth-first-search/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
Use a variation of DFS with parameters 'curent_vertex' and 'current_time'. | ||
</details> | ||
|
||
<details> | ||
<summary>Hint 2</summary> | ||
Update the probability considering to jump to one of the children vertices. | ||
</details> |
56 changes: 56 additions & 0 deletions
problems/generate-a-string-with-characters-that-have-odd-counts/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
<!--|@author openset <openset.wang@gmail.com> |--> | ||
<!--|@link https://github.com/openset |--> | ||
<!--|@home https://github.com/openset/leetcode |--> | ||
<!--+----------------------------------------------------------------------+--> | ||
|
||
[< Previous](../maximum-sum-bst-in-binary-tree "Maximum Sum BST in Binary Tree") | ||
|
||
[Next >](../bulb-switcher-iii "Bulb Switcher III") | ||
|
||
## [1374. Generate a String With Characters That Have Odd Counts (Easy)](https://leetcode.com/problems/generate-a-string-with-characters-that-have-odd-counts "生成每种字符都是奇数个的字符串") | ||
|
||
<p>Given an integer <code>n</code>, <em>return a string with <code>n</code> characters such that each character in such string occurs <strong>an odd number of times</strong></em>.</p> | ||
|
||
<p>The returned string must contain only lowercase English letters. If there are multiples valid strings, return <strong>any</strong> of them. </p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 4 | ||
<strong>Output:</strong> "pppz" | ||
<strong>Explanation:</strong> "pppz" is a valid string since the character 'p' occurs three times and the character 'z' occurs once. Note that there are many other valid strings such as "ohhh" and "love". | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 2 | ||
<strong>Output:</strong> "xy" | ||
<strong>Explanation:</strong> "xy" is a valid string since the characters 'x' and 'y' occur once. Note that there are many other valid strings such as "ag" and "ur". | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> n = 7 | ||
<strong>Output:</strong> "holasss" | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= n <= 500</code></li> | ||
</ul> | ||
|
||
### Related Topics | ||
[[String](../../tag/string/README.md)] | ||
|
||
### Hints | ||
<details> | ||
<summary>Hint 1</summary> | ||
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''. | ||
</details> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.