Skip to content

Commit f9533e5

Browse files
author
openset
committed
Add: new
1 parent 2ff1a3c commit f9533e5

File tree

28 files changed

+299
-13
lines changed

28 files changed

+299
-13
lines changed

Diff for: README.md

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1107">1107</span> | [New Users Daily Count](https://leetcode.com/problems/new-users-daily-count) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/new-users-daily-count) | Medium |
58+
| <span id="1106">1106</span> | [Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression "解析布尔表达式") | [Go](https://github.com/openset/leetcode/tree/master/problems/parsing-a-boolean-expression) | Hard |
59+
| <span id="1105">1105</span> | [Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves "填充书架") | [Go](https://github.com/openset/leetcode/tree/master/problems/filling-bookcase-shelves) | Medium |
60+
| <span id="1104">1104</span> | [Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree "二叉树寻路") | [Go](https://github.com/openset/leetcode/tree/master/problems/path-in-zigzag-labelled-binary-tree) | Medium |
61+
| <span id="1103">1103</span> | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people "分糖果 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/distribute-candies-to-people) | Easy |
5762
| <span id="1102">1102</span> | [Path With Maximum Minimum Value](https://leetcode.com/problems/path-with-maximum-minimum-value "得分最高的路径") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-minimum-value) | Medium |
5863
| <span id="1101">1101</span> | [The Earliest Moment When Everyone Become Friends](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends "彼此熟识的最早时间") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/the-earliest-moment-when-everyone-become-friends) | Medium |
5964
| <span id="1100">1100</span> | [Find K-Length Substrings With No Repeated Characters](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters "长度为 K 的无重复字符子串") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/find-k-length-substrings-with-no-repeated-characters) | Medium |

Diff for: problems/binary-tree-inorder-traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<p><strong>Follow up:</strong> Recursive solution is trivial, could you do it iteratively?</p>
2929

3030
### Related Topics
31+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
3132
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3233
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
33-
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
3434

3535
### Similar Questions
3636
1. [Validate Binary Search Tree](https://github.com/openset/leetcode/tree/master/problems/validate-binary-search-tree) (Medium)

Diff for: problems/construct-binary-tree-from-inorder-and-postorder-traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ postorder = [9,15,7,20,3]</pre>
3333
</pre>
3434

3535
### Related Topics
36+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3637
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
3738
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
38-
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3939

4040
### Similar Questions
4141
1. [Construct Binary Tree from Preorder and Inorder Traversal](https://github.com/openset/leetcode/tree/master/problems/construct-binary-tree-from-preorder-and-inorder-traversal) (Medium)

Diff for: problems/construct-binary-tree-from-preorder-and-inorder-traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ inorder = [9,3,15,20,7]</pre>
3232
15 7</pre>
3333

3434
### Related Topics
35+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3536
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
3637
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
37-
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3838

3939
### Similar Questions
4040
1. [Construct Binary Tree from Inorder and Postorder Traversal](https://github.com/openset/leetcode/tree/master/problems/construct-binary-tree-from-inorder-and-postorder-traversal) (Medium)

Diff for: problems/distribute-candies-to-people/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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](https://github.com/openset/leetcode/tree/master/problems/path-with-maximum-minimum-value "Path With Maximum Minimum Value")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/path-in-zigzag-labelled-binary-tree "Path In Zigzag Labelled Binary Tree")
11+
12+
## 1103. Distribute Candies to People (Easy)
13+
14+
<p>We distribute some&nbsp;number of <code>candies</code>, to a row of <strong><code>n =&nbsp;num_people</code></strong>&nbsp;people in the following way:</p>
15+
16+
<p>We then give 1 candy to the first person, 2 candies to the second person, and so on until we give <code>n</code>&nbsp;candies to the last person.</p>
17+
18+
<p>Then, we go back to the start of the row, giving <code>n&nbsp;+ 1</code> candies to the first person, <code>n&nbsp;+ 2</code> candies to the second person, and so on until we give <code>2 * n</code>&nbsp;candies to the last person.</p>
19+
20+
<p>This process repeats (with us giving one more candy each time, and moving to the start of the row after we reach the end) until we run out of candies.&nbsp; The last person will receive all of our remaining candies (not necessarily one more than the previous gift).</p>
21+
22+
<p>Return an array (of length <code>num_people</code>&nbsp;and sum <code>candies</code>) that represents the final distribution of candies.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> candies = 7, num_people = 4
29+
<strong>Output:</strong> [1,2,3,1]
30+
<strong>Explanation:</strong>
31+
On the first turn, ans[0] += 1, and the array is [1,0,0,0].
32+
On the second turn, ans[1] += 2, and the array is [1,2,0,0].
33+
On the third turn, ans[2] += 3, and the array is [1,2,3,0].
34+
On the fourth turn, ans[3] += 1 (because there is only one candy left), and the final array is [1,2,3,1].
35+
</pre>
36+
37+
<p><strong>Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> candies = 10, num_people = 3
41+
<strong>Output:</strong> [5,2,3]
42+
<strong>Explanation: </strong>
43+
On the first turn, ans[0] += 1, and the array is [1,0,0].
44+
On the second turn, ans[1] += 2, and the array is [1,2,0].
45+
On the third turn, ans[2] += 3, and the array is [1,2,3].
46+
On the fourth turn, ans[0] += 4, and the final array is [5,2,3].
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li>1 &lt;= candies &lt;= 10^9</li>
54+
<li>1 &lt;= num_people &lt;= 1000</li>
55+
</ul>
56+
57+
### Related Topics
58+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
59+
60+
### Hints
61+
<details>
62+
<summary>Hint 1</summary>
63+
Give candy to everyone each "turn" first [until you can't], then give candy to one person per turn.
64+
</details>

Diff for: problems/filling-bookcase-shelves/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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](https://github.com/openset/leetcode/tree/master/problems/path-in-zigzag-labelled-binary-tree "Path In Zigzag Labelled Binary Tree")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/parsing-a-boolean-expression "Parsing A Boolean Expression")
11+
12+
## 1105. Filling Bookcase Shelves (Medium)
13+
14+
<p>We have a sequence of <code>books</code>: the <code>i</code>-th book has thickness <code>books[i][0]</code> and height <code>books[i][1]</code>.</p>
15+
16+
<p>We want to place these books <strong>in order</strong>&nbsp;onto bookcase shelves that have total width <code>shelf_width</code>.</p>
17+
18+
<p>We choose&nbsp;some of the books to place on this shelf (such that the sum of their thickness is <code>&lt;= shelf_width</code>), then build another level of shelf of the bookcase so that the total height of the bookcase has increased by the maximum height of the books we just put down.&nbsp; We repeat this process until there are no more books to place.</p>
19+
20+
<p>Note again that at each step of the above&nbsp;process, <u>the order of the books we place is the same order as the given sequence of books</u>.&nbsp; For example, if we have an ordered list of 5&nbsp;books, we might place the first and second book onto the first shelf, the third book on the second shelf, and the fourth and fifth book on the last shelf.</p>
21+
22+
<p>Return the minimum possible height that the total bookshelf can be after placing shelves in this manner.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
26+
<img alt="" src="https://assets.leetcode.com/uploads/2019/06/24/shelves.png" style="width: 250px; height: 370px;" />
27+
<pre>
28+
<strong>Input:</strong> books = [[1,1],[2,3],[2,3],[1,1],[1,1],[1,1],[1,2]], shelf_width = 4
29+
<strong>Output:</strong> 6
30+
<strong>Explanation:</strong>
31+
The sum of the heights of the 3 shelves are 1 + 3 + 2 = 6.
32+
Notice that book number 2 does not have to be on the first shelf.
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>1 &lt;= books.length &lt;= 1000</code></li>
40+
<li><code>1 &lt;= books[i][0] &lt;= shelf_width &lt;= 1000</code></li>
41+
<li><code>1 &lt;= books[i][1] &lt;= 1000</code></li>
42+
</ul>
43+
44+
### Related Topics
45+
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
46+
47+
### Hints
48+
<details>
49+
<summary>Hint 1</summary>
50+
Use dynamic programming: dp(i) will be the answer to the problem for books[i:].
51+
</details>

Diff for: problems/find-k-length-substrings-with-no-repeated-characters/README.md

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

1010
[Next >](https://github.com/openset/leetcode/tree/master/problems/the-earliest-moment-when-everyone-become-friends "The Earliest Moment When Everyone Become Friends")
1111

12-
## 5022. Find K-Length Substrings With No Repeated Characters (Medium)
12+
## 1100. Find K-Length Substrings With No Repeated Characters (Medium)
1313

1414
<p>Given a string <code>S</code>, return the number of substrings of length <code>K</code> with no repeated characters.</p>
1515

Diff for: problems/largest-rectangle-in-histogram/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
</pre>
3434

3535
### Related Topics
36-
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3736
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
37+
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3838

3939
### Similar Questions
4040
1. [Maximal Rectangle](https://github.com/openset/leetcode/tree/master/problems/maximal-rectangle) (Hard)

Diff for: problems/maximal-rectangle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</pre>
2828

2929
### Related Topics
30-
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3130
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3231
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
3332
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
33+
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3434

3535
### Similar Questions
3636
1. [Largest Rectangle in Histogram](https://github.com/openset/leetcode/tree/master/problems/largest-rectangle-in-histogram) (Hard)

Diff for: problems/new-users-daily-count/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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](https://github.com/openset/leetcode/tree/master/problems/parsing-a-boolean-expression "Parsing A Boolean Expression")
9+
                
10+
Next >
11+
12+
## 1107. New Users Daily Count (Medium)
13+
14+

Diff for: problems/new-users-daily-count/mysql_schemas.sql

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Create table If Not Exists Traffic (user_id int, activity ENUM('login', 'logout', 'jobs', 'groups', 'homepage'), activity_date date);
2+
Truncate table Traffic;
3+
insert into Traffic (user_id, activity, activity_date) values ('1', 'login', '2019-05-01');
4+
insert into Traffic (user_id, activity, activity_date) values ('1', 'homepage', '2019-05-01');
5+
insert into Traffic (user_id, activity, activity_date) values ('1', 'logout', '2019-05-01');
6+
insert into Traffic (user_id, activity, activity_date) values ('2', 'login', '2019-06-21');
7+
insert into Traffic (user_id, activity, activity_date) values ('2', 'logout', '2019-06-21');
8+
insert into Traffic (user_id, activity, activity_date) values ('3', 'login', '2019-01-01');
9+
insert into Traffic (user_id, activity, activity_date) values ('3', 'jobs', '2019-01-01');
10+
insert into Traffic (user_id, activity, activity_date) values ('3', 'logout', '2019-01-01');
11+
insert into Traffic (user_id, activity, activity_date) values ('4', 'login', '2019-06-21');
12+
insert into Traffic (user_id, activity, activity_date) values ('4', 'groups', '2019-06-21');
13+
insert into Traffic (user_id, activity, activity_date) values ('4', 'logout', '2019-06-21');
14+
insert into Traffic (user_id, activity, activity_date) values ('5', 'login', '2019-03-01');
15+
insert into Traffic (user_id, activity, activity_date) values ('5', 'logout', '2019-03-01');
16+
insert into Traffic (user_id, activity, activity_date) values ('5', 'login', '2019-06-21');
17+
insert into Traffic (user_id, activity, activity_date) values ('5', 'logout', '2019-06-21');

Diff for: problems/parsing-a-boolean-expression/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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](https://github.com/openset/leetcode/tree/master/problems/filling-bookcase-shelves "Filling Bookcase Shelves")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/new-users-daily-count "New Users Daily Count")
11+
12+
## 1106. Parsing A Boolean Expression (Hard)
13+
14+
<p>Return the result of evaluating a given boolean <code>expression</code>, represented as a string.</p>
15+
16+
<p>An expression can either be:</p>
17+
18+
<ul>
19+
<li><code>&quot;t&quot;</code>, evaluating to <code>True</code>;</li>
20+
<li><code>&quot;f&quot;</code>, evaluating to <code>False</code>;</li>
21+
<li><code>&quot;!(expr)&quot;</code>, evaluating to the logical NOT of the inner expression <code>expr</code>;</li>
22+
<li><code>&quot;&amp;(expr1,expr2,...)&quot;</code>, evaluating to the logical AND of 2 or more inner expressions <code>expr1, expr2, ...</code>;</li>
23+
<li><code>&quot;|(expr1,expr2,...)&quot;</code>, evaluating to the logical OR of 2 or more inner expressions <code>expr1, expr2, ...</code></li>
24+
</ul>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> expression = &quot;!(f)&quot;
31+
<strong>Output:</strong> true
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> expression = &quot;|(f,t)&quot;
38+
<strong>Output:</strong> true
39+
</pre>
40+
41+
<p><strong>Example 3:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> expression = &quot;&amp;(t,f)&quot;
45+
<strong>Output:</strong> false
46+
</pre>
47+
48+
<p><strong>Example 4:</strong></p>
49+
50+
<pre>
51+
<strong>Input:</strong> expression = &quot;|(&amp;(t,f,t),!(t))&quot;
52+
<strong>Output:</strong> false
53+
</pre>
54+
55+
<p>&nbsp;</p>
56+
<p><strong>Constraints:</strong></p>
57+
58+
<ul>
59+
<li><code>1 &lt;= expression.length &lt;= 20000</code></li>
60+
<li><code>expression[i]</code>&nbsp;consists of characters in <code>{&#39;(&#39;, &#39;)&#39;, &#39;&amp;&#39;, &#39;|&#39;, &#39;!&#39;, &#39;t&#39;, &#39;f&#39;, &#39;,&#39;}</code>.</li>
61+
<li><code>expression</code> is a valid expression representing a boolean, as given in the description.</li>
62+
</ul>
63+
64+
### Related Topics
65+
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
66+
67+
### Hints
68+
<details>
69+
<summary>Hint 1</summary>
70+
Write a function "parse" which calls helper functions "parse_or", "parse_and", "parse_not".
71+
</details>
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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](https://github.com/openset/leetcode/tree/master/problems/distribute-candies-to-people "Distribute Candies to People")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/filling-bookcase-shelves "Filling Bookcase Shelves")
11+
12+
## 1104. Path In Zigzag Labelled Binary Tree (Medium)
13+
14+
<p>In an infinite binary tree where every node has two children, the nodes are labelled in row order.</p>
15+
16+
<p>In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left.</p>
17+
18+
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/06/24/tree.png" style="width: 300px; height: 138px;" /></p>
19+
20+
<p>Given the <code>label</code> of a node in this tree, return the labels in the path from the root of the tree to the&nbsp;node with that <code>label</code>.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> label = 14
27+
<strong>Output:</strong> [1,3,4,14]
28+
</pre>
29+
30+
<p><strong>Example 2:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> label = 26
34+
<strong>Output:</strong> [1,2,6,10,26]
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= label &lt;= 10^6</code></li>
42+
</ul>
43+
44+
### Related Topics
45+
[[Tree](https://github.com/openset/leetcode/tree/master/tag/tree/README.md)]
46+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
47+
48+
### Hints
49+
<details>
50+
<summary>Hint 1</summary>
51+
Based on the label of the current node, find what the label must be for the parent of that node.
52+
</details>

Diff for: problems/path-with-maximum-minimum-value/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/the-earliest-moment-when-everyone-become-friends "The Earliest Moment When Everyone Become Friends")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/distribute-candies-to-people "Distribute Candies to People")
1111

12-
## 5035. Path With Maximum Minimum Value (Medium)
12+
## 1102. Path With Maximum Minimum Value (Medium)
1313

1414
<p>Given a&nbsp;matrix of integers <code>A</code>&nbsp;with&nbsp;<font face="monospace">R</font>&nbsp;rows and <font face="monospace">C</font>&nbsp;columns, find&nbsp;the <strong>maximum</strong>&nbsp;score&nbsp;of a path starting at&nbsp;<code>[0,0]</code>&nbsp;and ending at <code>[R-1,C-1]</code>.</p>
1515

0 commit comments

Comments
 (0)