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

Commit d51c69e

Browse files
author
Shuo
authored
Merge pull request #787 from openset/develop
A: new
2 parents cf46bc8 + 4ceac42 commit d51c69e

File tree

35 files changed

+925
-64
lines changed

35 files changed

+925
-64
lines changed

‎README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,21 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65-
| <span id="1425">1425</span> | [Constrained Subset Sum](https://leetcode.com/problems/constrained-subset-sum "带限制的子序列和") | [Go](problems/constrained-subset-sum) | Hard |
65+
| <span id="1439">1439</span> | [Find the Kth Smallest Sum of a Matrix With Sorted Rows](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows "有序矩阵中的第 k 个最小数组和") | [Go](problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows) | Hard |
66+
| <span id="1438">1438</span> | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "绝对差不超过限制的最长连续子数组") | [Go](problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) | Medium |
67+
| <span id="1437">1437</span> | [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素") | [Go](problems/check-if-all-1s-are-at-least-length-k-places-away) | Medium |
68+
| <span id="1436">1436</span> | [Destination City](https://leetcode.com/problems/destination-city "旅行终点站") | [Go](problems/destination-city) | Easy |
69+
| <span id="1435">1435</span> | [Create a Session Bar Chart](https://leetcode.com/problems/create-a-session-bar-chart) 🔒 | [MySQL](problems/create-a-session-bar-chart) | Easy |
70+
| <span id="1434">1434</span> | [Number of Ways to Wear Different Hats to Each Other](https://leetcode.com/problems/number-of-ways-to-wear-different-hats-to-each-other "每个人戴不同帽子的方案数") | [Go](problems/number-of-ways-to-wear-different-hats-to-each-other) | Hard |
71+
| <span id="1433">1433</span> | [Check If a String Can Break Another String](https://leetcode.com/problems/check-if-a-string-can-break-another-string "检查一个字符串是否可以打破另一个字符串") | [Go](problems/check-if-a-string-can-break-another-string) | Medium |
72+
| <span id="1432">1432</span> | [Max Difference You Can Get From Changing an Integer](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer "改变一个整数能得到的最大差值") | [Go](problems/max-difference-you-can-get-from-changing-an-integer) | Medium |
73+
| <span id="1431">1431</span> | [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies "拥有最多糖果的孩子") | [Go](problems/kids-with-the-greatest-number-of-candies) | Easy |
74+
| <span id="1430">1430</span> | [Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) 🔒 | [Go](problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) | Medium |
75+
| <span id="1429">1429</span> | [First Unique Number](https://leetcode.com/problems/first-unique-number) 🔒 | [Go](problems/first-unique-number) | Medium |
76+
| <span id="1428">1428</span> | [Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one) 🔒 | [Go](problems/leftmost-column-with-at-least-a-one) | Medium |
77+
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts) 🔒 | [Go](problems/perform-string-shifts) | Easy |
78+
| <span id="1426">1426</span> | [Counting Elements](https://leetcode.com/problems/counting-elements "数元素") 🔒 | [Go](problems/counting-elements) | Easy |
79+
| <span id="1425">1425</span> | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和") | [Go](problems/constrained-subsequence-sum) | Hard |
6680
| <span id="1424">1424</span> | [Diagonal Traverse II](https://leetcode.com/problems/diagonal-traverse-ii "对角线遍历 II") | [Go](problems/diagonal-traverse-ii) | Medium |
6781
| <span id="1423">1423</span> | [Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards "可获得的最大点数") | [Go](problems/maximum-points-you-can-obtain-from-cards) | Medium |
6882
| <span id="1422">1422</span> | [Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string "分割字符串的最大得分") | [Go](problems/maximum-score-after-splitting-a-string) | Easy |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../max-difference-you-can-get-from-changing-an-integer "Max Difference You Can Get From Changing an Integer")
9+
10+
[Next >](../number-of-ways-to-wear-different-hats-to-each-other "Number of Ways to Wear Different Hats to Each Other")
11+
12+
## [1433. Check If a String Can Break Another String (Medium)](https://leetcode.com/problems/check-if-a-string-can-break-another-string "检查一个字符串是否可以打破另一个字符串")
13+
14+
<p>Given two strings: <code>s1</code> and <code>s2</code> with the same&nbsp;size, check if some&nbsp;permutation of string <code>s1</code> can break&nbsp;some&nbsp;permutation of string <code>s2</code> or vice-versa (in other words <code>s2</code> can break <code>s1</code>).</p>
15+
16+
<p>A string <code>x</code>&nbsp;can break&nbsp;string <code>y</code>&nbsp;(both of size <code>n</code>) if <code>x[i] &gt;= y[i]</code>&nbsp;(in alphabetical order)&nbsp;for all <code>i</code>&nbsp;between <code>0</code> and <code>n-1</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> s1 = &quot;abc&quot;, s2 = &quot;xya&quot;
23+
<strong>Output:</strong> true
24+
<strong>Explanation:</strong> &quot;ayx&quot; is a permutation of s2=&quot;xya&quot; which can break to string &quot;abc&quot; which is a permutation of s1=&quot;abc&quot;.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> s1 = &quot;abe&quot;, s2 = &quot;acd&quot;
31+
<strong>Output:</strong> false
32+
<strong>Explanation:</strong> All permutations for s1=&quot;abe&quot; are: &quot;abe&quot;, &quot;aeb&quot;, &quot;bae&quot;, &quot;bea&quot;, &quot;eab&quot; and &quot;eba&quot; and all permutation for s2=&quot;acd&quot; are: &quot;acd&quot;, &quot;adc&quot;, &quot;cad&quot;, &quot;cda&quot;, &quot;dac&quot; and &quot;dca&quot;. However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
33+
</pre>
34+
35+
<p><strong>Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> s1 = &quot;leetcodee&quot;, s2 = &quot;interview&quot;
39+
<strong>Output:</strong> true
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>s1.length == n</code></li>
47+
<li><code>s2.length == n</code></li>
48+
<li><code>1 &lt;= n &lt;= 10^5</code></li>
49+
<li>All strings consist of lowercase English letters.</li>
50+
</ul>
51+
52+
### Related Topics
53+
[[Greedy](../../tag/greedy/README.md)]
54+
[[String](../../tag/string/README.md)]
55+
56+
### Hints
57+
<details>
58+
<summary>Hint 1</summary>
59+
Sort both strings and then check if one of them can break the other.
60+
</details>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../first-unique-number "First Unique Number")
9+
10+
[Next >](../kids-with-the-greatest-number-of-candies "Kids With the Greatest Number of Candies")
11+
12+
## [1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree (Medium)](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree "")
13+
14+
15+
16+
### Related Topics
17+
[[Tree](../../tag/tree/README.md)]
18+
19+
### Hints
20+
<details>
21+
<summary>Hint 1</summary>
22+
Depth-first search (DFS) with the parameters: current node in the binary tree and current position in the array of integers.
23+
</details>
24+
25+
<details>
26+
<summary>Hint 2</summary>
27+
When reaching at final position check if it is a leaf node.
28+
</details>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../destination-city "Destination City")
9+
10+
[Next >](../longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit "Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit")
11+
12+
## [1437. Check If All 1's Are at Least Length K Places Away (Medium)](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away "是否所有 1 都至少相隔 k 个元素")
13+
14+
<p>Given an array <code>nums</code> of 0s and 1s and an integer <code>k</code>, return <code>True</code> if all 1&#39;s are at least <code>k</code> places away from each other, otherwise return <code>False</code>.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
18+
19+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/15/sample_1_1791.png" style="width: 214px; height: 90px;" /></strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [1,0,0,0,1,0,0,1], k = 2
23+
<strong>Output:</strong> true
24+
<strong>Explanation:</strong> Each of the 1s are at least 2 places away from each other.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/15/sample_2_1791.png" style="width: 160px; height: 86px;" /></strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums = [1,0,0,1,0,1], k = 2
33+
<strong>Output:</strong> false
34+
<strong>Explanation: </strong>The second 1 and third 1 are only one apart from each other.</pre>
35+
36+
<p><strong>Example 3:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> nums = [1,1,1,1,1], k = 0
40+
<strong>Output:</strong> true
41+
</pre>
42+
43+
<p><strong>Example 4:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> nums = [0,1,0,1], k = 1
47+
<strong>Output:</strong> true
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
55+
<li><code>0 &lt;= k &lt;= nums.length</code></li>
56+
<li><code>nums[i]</code>&nbsp;is&nbsp;<code>0</code>&nbsp;or&nbsp;<code>1</code></li>
57+
</ul>
58+
59+
### Related Topics
60+
[[Array](../../tag/array/README.md)]
61+
62+
### Hints
63+
<details>
64+
<summary>Hint 1</summary>
65+
Each time you find a number 1, check whether or not it is K or more places away from the next one. If it's not, return false.
66+
</details>
Lines changed: 73 additions & 0 deletions
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 <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../diagonal-traverse-ii "Diagonal Traverse II")
9+
10+
[Next >](../counting-elements "Counting Elements")
11+
12+
## [1425. Constrained Subsequence Sum (Hard)](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和")
13+
14+
<p>Given an integer array&nbsp;<code>nums</code>&nbsp;and an integer <code>k</code>, return the maximum sum of a <strong>non-empty</strong> subsequence&nbsp;of that array such that for every&nbsp;two <strong>consecutive</strong> integers in the subsequence,&nbsp;<code>nums[i]</code>&nbsp;and&nbsp;<code>nums[j]</code>, where&nbsp;<code>i &lt; j</code>, the condition&nbsp;<code>j - i &lt;= k</code>&nbsp;is satisfied.</p>
15+
16+
<p>A&nbsp;<em>subsequence</em>&nbsp;of an array is&nbsp;obtained by deleting some number of elements (can be&nbsp;zero) from the array, leaving the remaining elements in their original order.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [10,2,-10,5,20], k = 2
23+
<strong>Output:</strong> 37
24+
<b>Explanation:</b> The subsequence is [10, 2, 5, 20].
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> nums = [-1,-2,-3], k = 1
31+
<strong>Output:</strong> -1
32+
<b>Explanation:</b> The subsequence must be non-empty, so we choose the largest number.
33+
</pre>
34+
35+
<p><strong>Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> nums = [10,-2,-10,-5,20], k = 2
39+
<strong>Output:</strong> 23
40+
<b>Explanation:</b> The subsequence is [10, -2, -5, 20].
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10^5</code></li>
48+
<li><code>-10^4&nbsp;&lt;= nums[i] &lt;= 10^4</code></li>
49+
</ul>
50+
51+
### Related Topics
52+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]
53+
54+
### Hints
55+
<details>
56+
<summary>Hint 1</summary>
57+
Use dynamic programming.
58+
</details>
59+
60+
<details>
61+
<summary>Hint 2</summary>
62+
Let dp[i] be the solution for the prefix of the array that ends at index i, if the element at index i is in the subsequence.
63+
</details>
64+
65+
<details>
66+
<summary>Hint 3</summary>
67+
dp[i] = nums[i] + max(0, dp[i-k], dp[i-k+1], ..., dp[i-1])
68+
</details>
69+
70+
<details>
71+
<summary>Hint 4</summary>
72+
Use a heap with the sliding window technique to optimize the dp.
73+
</details>

‎problems/construct-binary-search-tree-from-preorder-traversal/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<p><em>(Recall that a binary search tree&nbsp;is a binary tree where for every <font face="monospace">node</font>, any descendant of <code>node.left</code> has a value <code>&lt;</code>&nbsp;<code>node.val</code>, and any descendant of <code>node.right</code> has a value <code>&gt;</code>&nbsp;<code>node.val</code>.&nbsp; Also recall that a preorder traversal&nbsp;displays the value of the&nbsp;<code>node</code> first, then traverses <code>node.left</code>, then traverses <code>node.right</code>.)</em></p>
1717

18-
<p>&nbsp;</p>
18+
<p>It&#39;s guaranteed that for the given test cases there is always possible to find a binary search tree with the given requirements.</p>
1919

2020
<p><strong>Example 1:</strong></p>
2121

@@ -26,13 +26,13 @@
2626
</pre>
2727

2828
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
2930

30-
<p><strong>Note:</strong>&nbsp;</p>
31-
32-
<ol>
31+
<ul>
3332
<li><code>1 &lt;= preorder.length &lt;= 100</code></li>
33+
<li><code>1 &lt;= preorder[i]&nbsp;&lt;= 10^8</code></li>
3434
<li>The values of <code>preorder</code> are distinct.</li>
35-
</ol>
35+
</ul>
3636

3737
### Related Topics
3838
[[Tree](../../tag/tree/README.md)]

‎problems/counting-elements/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../constrained-subsequence-sum "Constrained Subsequence Sum")
9+
10+
[Next >](../perform-string-shifts "Perform String Shifts")
11+
12+
## [1426. Counting Elements (Easy)](https://leetcode.com/problems/counting-elements "数元素")
13+
14+
15+
16+
### Related Topics
17+
[[Array](../../tag/array/README.md)]
18+
19+
### Hints
20+
<details>
21+
<summary>Hint 1</summary>
22+
Use hashset to store all elements.
23+
</details>
24+
25+
<details>
26+
<summary>Hint 2</summary>
27+
Loop again to count all valid elements.
28+
</details>
Lines changed: 14 additions & 0 deletions
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 <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../number-of-ways-to-wear-different-hats-to-each-other "Number of Ways to Wear Different Hats to Each Other")
9+
10+
[Next >](../destination-city "Destination City")
11+
12+
## [1435. Create a Session Bar Chart (Easy)](https://leetcode.com/problems/create-a-session-bar-chart "")
13+
14+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Create table If Not Exists Sessions (session_id int, duration int);
2+
Truncate table Sessions;
3+
insert into Sessions (session_id, duration) values ('1', '30');
4+
insert into Sessions (session_id, duration) values ('2', '199');
5+
insert into Sessions (session_id, duration) values ('3', '299');
6+
insert into Sessions (session_id, duration) values ('4', '580');
7+
insert into Sessions (session_id, duration) values ('5', '1000');

0 commit comments

Comments
(0)

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