Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
awesee merged 1 commit into master from develop
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <span id="1375">1375</span> | [Bulb Switcher III](https://leetcode.com/problems/bulb-switcher-iii "灯泡开关 III") | [Go](problems/bulb-switcher-iii) | Medium |
| <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 |
| <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 |
| <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 |
| <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 |
| <span id="1370">1370</span> | [Increasing Decreasing String](https://leetcode.com/problems/increasing-decreasing-string "上升下降字符串") | [Go](problems/increasing-decreasing-string) | Easy |
| <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 |
| <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 |
| <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 |
| <span id="1366">1366</span> | [Rank Teams by Votes](https://leetcode.com/problems/rank-teams-by-votes "通过投票对团队排名") | [Go](problems/rank-teams-by-votes) | Medium |
Expand All @@ -76,7 +84,7 @@ LeetCode Problems' Solutions
| <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 |
| <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 |
| <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 |
| <span id="1355">1355</span> | [Activity Participants](https://leetcode.com/problems/activity-participants) 🔒 | [MySQL](problems/activity-participants) | Medium |
| <span id="1355">1355</span> | [Activity Participants](https://leetcode.com/problems/activity-participants "活动参与者") 🔒 | [MySQL](problems/activity-participants) | Medium |
| <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 |
| <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 |
| <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 |
Expand Down
2 changes: 1 addition & 1 deletion problems/activity-participants/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

<p>Table: <code>Friends</code></p>
<pre>
Expand Down
78 changes: 78 additions & 0 deletions problems/bulb-switcher-iii/README.md
View file Open in desktop
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&nbsp;color to blue</strong> only if it is on and all the previous bulbs (to the left)&nbsp;are turned on too.</p>

<p>Return the number of moments in&nbsp;which <strong>all&nbsp;turned on</strong> bulbs&nbsp;<strong>are blue.</strong></p>

<p>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>n ==&nbsp;light.length</code></li>
<li><code>1 &lt;= n &lt;= 5 * 10^4</code></li>
<li><code>light</code> is a permutation of&nbsp;&nbsp;<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>
1 change: 1 addition & 0 deletions problems/complement-of-base-10-integer/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

<ol>
<li><code>0 &lt;= N &lt; 10^9</code></li>
<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>
</ol>
</div>
</div>
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

## [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 "独特字符串")
## [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 "统计子串中的唯一字符")

<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 />
<br />
Expand Down
9 changes: 8 additions & 1 deletion problems/decompress-run-length-encoded-list/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

<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>
<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>

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

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

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,1,2,3]
<strong>Output:</strong> [1,3,3]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

Expand Down
View file Open in desktop
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, &#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, and &#39;u&#39; must appear an even number of times.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;eleetminicoworoep&quot;
<strong>Output:</strong> 13
<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>.
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;leetcodeisgreat&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> The longest substring is &quot;leetc&quot; which contains two e&#39;s.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;bcbcbc&quot;
<strong>Output:</strong> 6
<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.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= s.length &lt;= 5 x 10^5</code></li>
<li><code>s</code>&nbsp;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
View file Open in desktop
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&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>

<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>

<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>&nbsp;</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>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>edges.length == n-1</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>1 &lt;= edges[i][0], edges[i][1] &lt;= n</code></li>
<li><code>1 &lt;= t&nbsp;&lt;= 50</code></li>
<li><code>1 &lt;= target&nbsp;&lt;= 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>
View file Open in desktop
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&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>

<p>The returned string must contain only lowercase English letters. If there are multiples valid strings, return <strong>any</strong> of them. &nbsp;</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 4
<strong>Output:</strong> &quot;pppz&quot;
<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;.
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> &quot;xy&quot;
<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;.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> n = 7
<strong>Output:</strong> &quot;holasss&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 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>
Loading

AltStyle によって変換されたページ (->オリジナル) /