Skip to content

Commit dc078f4

Browse files
author
Shuo
committed
A: new
1 parent 14db544 commit dc078f4

File tree

74 files changed

+1571
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1571
-352
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,27 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73-
| <span id="1628">1628</span> | [Design an Expression Tree With Evaluate Function](https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function) 🔒 | [Go](problems/design-an-expression-tree-with-evaluate-function) | Medium |
73+
| <span id="1643">1643</span> | [Kth Smallest Instructions](https://leetcode.com/problems/kth-smallest-instructions "第 K 条最小指令") | [Go](problems/kth-smallest-instructions) | Hard |
74+
| <span id="1642">1642</span> | [Furthest Building You Can Reach](https://leetcode.com/problems/furthest-building-you-can-reach "可以到达的最远建筑") | [Go](problems/furthest-building-you-can-reach) | Medium |
75+
| <span id="1641">1641</span> | [Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings "统计字典序元音字符串的数目") | [Go](problems/count-sorted-vowel-strings) | Medium |
76+
| <span id="1640">1640</span> | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation "能否连接形成数组") | [Go](problems/check-array-formation-through-concatenation) | Easy |
77+
| <span id="1639">1639</span> | [Number of Ways to Form a Target String Given a Dictionary](https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary "通过给定词典构造目标字符串的方案数") | [Go](problems/number-of-ways-to-form-a-target-string-given-a-dictionary) | Hard |
78+
| <span id="1638">1638</span> | [Count Substrings That Differ by One Character](https://leetcode.com/problems/count-substrings-that-differ-by-one-character "统计只差一个字符的子串数目") | [Go](problems/count-substrings-that-differ-by-one-character) | Medium |
79+
| <span id="1637">1637</span> | [Widest Vertical Area Between Two Points Containing No Points](https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points "两点之间不包含任何点的最宽垂直面积") | [Go](problems/widest-vertical-area-between-two-points-containing-no-points) | Medium |
80+
| <span id="1636">1636</span> | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency "按照频率将数组升序排序") | [Go](problems/sort-array-by-increasing-frequency) | Easy |
81+
| <span id="1635">1635</span> | [Hopper Company Queries I](https://leetcode.com/problems/hopper-company-queries-i) 🔒 | [MySQL](problems/hopper-company-queries-i) | Hard |
82+
| <span id="1634">1634</span> | [Add Two Polynomials Represented as Linked Lists](https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists) 🔒 | [Go](problems/add-two-polynomials-represented-as-linked-lists) | Medium |
83+
| <span id="1633">1633</span> | [Percentage of Users Attended a Contest](https://leetcode.com/problems/percentage-of-users-attended-a-contest "各赛事的用户注册率") 🔒 | [MySQL](problems/percentage-of-users-attended-a-contest) | Easy |
84+
| <span id="1632">1632</span> | [Rank Transform of a Matrix](https://leetcode.com/problems/rank-transform-of-a-matrix "矩阵转换后的秩") | [Go](problems/rank-transform-of-a-matrix) | Hard |
85+
| <span id="1631">1631</span> | [Path With Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort "最小体力消耗路径") | [Go](problems/path-with-minimum-effort) | Medium |
86+
| <span id="1630">1630</span> | [Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays "等差子数组") | [Go](problems/arithmetic-subarrays) | Medium |
87+
| <span id="1629">1629</span> | [Slowest Key](https://leetcode.com/problems/slowest-key "按键持续时间最长的键") | [Go](problems/slowest-key) | Easy |
88+
| <span id="1628">1628</span> | [Design an Expression Tree With Evaluate Function](https://leetcode.com/problems/design-an-expression-tree-with-evaluate-function "设计带解析函数的表达式树") 🔒 | [Go](problems/design-an-expression-tree-with-evaluate-function) | Medium |
7489
| <span id="1627">1627</span> | [Graph Connectivity With Threshold](https://leetcode.com/problems/graph-connectivity-with-threshold "带阈值的图连通性") | [Go](problems/graph-connectivity-with-threshold) | Hard |
7590
| <span id="1626">1626</span> | [Best Team With No Conflicts](https://leetcode.com/problems/best-team-with-no-conflicts "无矛盾的最佳球队") | [Go](problems/best-team-with-no-conflicts) | Medium |
7691
| <span id="1625">1625</span> | [Lexicographically Smallest String After Applying Operations](https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations "执行操作后字典序最小的字符串") | [Go](problems/lexicographically-smallest-string-after-applying-operations) | Medium |
7792
| <span id="1624">1624</span> | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters "两个相同字符之间的最长子字符串") | [Go](problems/largest-substring-between-two-equal-characters) | Easy |
78-
| <span id="1623">1623</span> | [All Valid Triplets That Can Represent a Country](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country) 🔒 | [MySQL](problems/all-valid-triplets-that-can-represent-a-country) | Easy |
93+
| <span id="1623">1623</span> | [All Valid Triplets That Can Represent a Country](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country "三人国家代表队") 🔒 | [MySQL](problems/all-valid-triplets-that-can-represent-a-country) | Easy |
7994
| <span id="1622">1622</span> | [Fancy Sequence](https://leetcode.com/problems/fancy-sequence "奇妙序列") | [Go](problems/fancy-sequence) | Hard |
8095
| <span id="1621">1621</span> | [Number of Sets of K Non-Overlapping Line Segments](https://leetcode.com/problems/number-of-sets-of-k-non-overlapping-line-segments "大小为 K 的不重叠线段的数目") | [Go](problems/number-of-sets-of-k-non-overlapping-line-segments) | Medium |
8196
| <span id="1620">1620</span> | [Coordinate With Maximum Network Quality](https://leetcode.com/problems/coordinate-with-maximum-network-quality "网络信号最好的坐标") | [Go](problems/coordinate-with-maximum-network-quality) | Medium |
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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](../percentage-of-users-attended-a-contest "Percentage of Users Attended a Contest")
9+
                
10+
[Next >](../hopper-company-queries-i "Hopper Company Queries I")
11+
12+
## [1634. Add Two Polynomials Represented as Linked Lists (Medium)](https://leetcode.com/problems/add-two-polynomials-represented-as-linked-lists "")
13+
14+
15+
16+
### Related Topics
17+
[[Linked List](../../tag/linked-list/README.md)]
18+
19+
### Hints
20+
<details>
21+
<summary>Hint 1</summary>
22+
Process both linked lists at the same time
23+
</details>
24+
25+
<details>
26+
<summary>Hint 2</summary>
27+
If the current power of the two heads is equal, add this power with the sum of the coefficients to the answer list.
28+
</details>
29+
30+
<details>
31+
<summary>Hint 3</summary>
32+
If one head has a larger power, add this power to the answer list and move only this head.
33+
</details>

problems/all-valid-triplets-that-can-represent-a-country/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
[Next >](../largest-substring-between-two-equal-characters "Largest Substring Between Two Equal Characters")
1111

12-
## [1623. All Valid Triplets That Can Represent a Country (Easy)](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country "")
12+
## [1623. All Valid Triplets That Can Represent a Country (Easy)](https://leetcode.com/problems/all-valid-triplets-that-can-represent-a-country "三人国家代表队")
1313

1414

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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](../slowest-key "Slowest Key")
9+
                
10+
[Next >](../path-with-minimum-effort "Path With Minimum Effort")
11+
12+
## [1630. Arithmetic Subarrays (Medium)](https://leetcode.com/problems/arithmetic-subarrays "等差子数组")
13+
14+
<p>A sequence of numbers is called <strong>arithmetic</strong> if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence <code>s</code> is arithmetic if and only if <code>s[i+1] - s[i] == s[1] - s[0] </code>for all valid <code>i</code>.</p>
15+
16+
<p>For example, these are <strong>arithmetic</strong> sequences:</p>
17+
18+
<pre>
19+
1, 3, 5, 7, 9
20+
7, 7, 7, 7
21+
3, -1, -5, -9</pre>
22+
23+
<p>The following sequence is not <strong>arithmetic</strong>:</p>
24+
25+
<pre>
26+
1, 1, 2, 5, 7</pre>
27+
28+
<p>You are given an array of <code>n</code> integers, <code>nums</code>, and two arrays of <code>m</code> integers each, <code>l</code> and <code>r</code>, representing the <code>m</code> range queries, where the <code>i<sup>th</sup></code> query is the range <code>[l[i], r[i]]</code>. All the arrays are <strong>0-indexed</strong>.</p>
29+
30+
<p>Return <em>a list of </em><code>boolean</code> <em>elements</em> <code>answer</code><em>, where</em> <code>answer[i]</code> <em>is</em> <code>true</code> <em>if the subarray</em> <code>nums[l[i]], nums[l[i]+1], ... , nums[r[i]]</code><em> can be <strong>rearranged</strong> to form an <strong>arithmetic</strong> sequence, and</em> <code>false</code> <em>otherwise.</em></p>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Example 1:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> nums = <code>[4,6,5,9,3,7]</code>, l = <code>[0,0,2]</code>, r = <code>[2,3,5]</code>
37+
<strong>Output:</strong> <code>[true,false,true]</code>
38+
<strong>Explanation:</strong>
39+
In the 0<sup>th</sup> query, the subarray is [4,6,5]. This can be rearranged as [6,5,4], which is an arithmetic sequence.
40+
In the 1<sup>st</sup> query, the subarray is [4,6,5,9]. This cannot be rearranged as an arithmetic sequence.
41+
In the 2<sup>nd</sup> query, the subarray is <code>[5,9,3,7]. This</code> can be rearranged as <code>[3,5,7,9]</code>, which is an arithmetic sequence.</pre>
42+
43+
<p><strong>Example 2:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]
47+
<strong>Output:</strong> [false,true,false,false,true,true]
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>n == nums.length</code></li>
55+
<li><code>m == l.length</code></li>
56+
<li><code>m == r.length</code></li>
57+
<li><code>2 &lt;= n &lt;= 500</code></li>
58+
<li><code>1 &lt;= m &lt;= 500</code></li>
59+
<li><code>0 &lt;= l[i] &lt; r[i] &lt; n</code></li>
60+
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Sort](../../tag/sort/README.md)]
65+
66+
### Hints
67+
<details>
68+
<summary>Hint 1</summary>
69+
To check if a given sequence is arithmetic, just check that the difference between every two consecutive elements is the same.
70+
</details>
71+
72+
<details>
73+
<summary>Hint 2</summary>
74+
If and only if a set of numbers can make an arithmetic sequence, then its sorted version makes an arithmetic sequence. So to check a set of numbers, sort it, and check if that sequence is arithmetic.
75+
</details>
76+
77+
<details>
78+
<summary>Hint 3</summary>
79+
For each query, get the corresponding set of numbers which will be the sub-array represented by the query, sort it, and check if the result sequence is arithmetic.
80+
</details>

problems/array-partition-i/README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,36 @@
1111

1212
## [561. Array Partition I (Easy)](https://leetcode.com/problems/array-partition-i "数组拆分 I")
1313

14-
<p>
15-
Given an array of <b>2n</b> integers, your task is to group these integers into <b>n</b> pairs of integer, say (a<sub>1</sub>, b<sub>1</sub>), (a<sub>2</sub>, b<sub>2</sub>), ..., (a<sub>n</sub>, b<sub>n</sub>) which makes sum of min(a<sub>i</sub>, b<sub>i</sub>) for all i from 1 to n as large as possible.
16-
</p>
14+
<p>Given an integer array <code>nums</code> of <code>2n</code> integers, group these integers into <code>n</code> pairs <code>(a<sub>1</sub>, b<sub>1</sub>), (a<sub>2</sub>, b<sub>2</sub>), ..., (a<sub>n</sub>, b<sub>n</sub>)</code> such that the sum of <code>min(a<sub>i</sub>, b<sub>i</sub>)</code> for all <code>i</code> is <strong>maximized</strong>. Return<em> the maximized sum</em>.</p>
15+
16+
<p>&nbsp;</p>
17+
<p><strong>Example 1:</strong></p>
1718

18-
<p><b>Example 1:</b><br />
1919
<pre>
20-
<b>Input:</b> [1,4,3,2]
20+
<strong>Input:</strong> nums = [1,4,3,2]
21+
<strong>Output:</strong> 4
22+
<strong>Explanation:</strong> All possible pairings (ignoring the ordering of elements) are:
23+
1. (1, 4), (2, 3) -&gt; min(1, 4) + min(2, 3) = 1 + 2 = 3
24+
2. (1, 3), (2, 4) -&gt; min(1, 3) + min(2, 4) = 1 + 2 = 3
25+
3. (1, 2), (3, 4) -&gt; min(1, 2) + min(3, 4) = 1 + 3 = 4
26+
So the maximum possible sum is 4.</pre>
27+
28+
<p><strong>Example 2:</strong></p>
2129

22-
<b>Output:</b> 4
23-
<b>Explanation:</b> n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
30+
<pre>
31+
<strong>Input:</strong> nums = [6,2,6,5,1,2]
32+
<strong>Output:</strong> 9
33+
<strong>Explanation:</strong> The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.
2434
</pre>
25-
</p>
26-
27-
<p><b>Note:</b><br>
28-
<ol>
29-
<li><b>n</b> is a positive integer, which is in the range of [1, 10000].</li>
30-
<li>All the integers in the array will be in the range of [-10000, 10000].</li>
31-
</ol>
32-
</p>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
41+
<li><code>nums.length == 2 * n</code></li>
42+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
43+
</ul>
3344

3445
### Related Topics
3546
[[Array](../../tag/array/README.md)]

problems/binary-tree-tilt/README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,52 @@
1111

1212
## [563. Binary Tree Tilt (Easy)](https://leetcode.com/problems/binary-tree-tilt "二叉树的坡度")
1313

14-
<p>Given a binary tree, return the tilt of the <b>whole tree</b>.</p>
14+
<p>Given the <code>root</code> of a binary tree, return <em>the sum of every tree node&#39;s <strong>tilt</strong>.</em></p>
1515

16-
<p>The tilt of a <b>tree node</b> is defined as the <b>absolute difference</b> between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0.</p>
16+
<p>The <strong>tilt</strong> of a tree node is the <b>absolute difference</b> between the sum of all left subtree node <strong>values</strong> and all right subtree node <strong>values</strong>. If a node does not have a left child, then the sum of the left subtree node <strong>values</strong> is treated as <code>0</code>. The rule is similar if there the node does not have a right child.</p>
1717

18-
<p>The tilt of the <b>whole tree</b> is defined as the sum of all nodes' tilt.</p>
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/20/tilt1.jpg" style="width: 712px; height: 182px;" />
21+
<pre>
22+
<strong>Input:</strong> root = [1,2,3]
23+
<strong>Output:</strong> 1
24+
<strong>Explanation:</strong>
25+
Tilt of node 2 : |0-0| = 0 (no children)
26+
Tilt of node 3 : |0-0| = 0 (no children)
27+
Tile of node 1 : |2-3| = 1 (left subtree is just left child, so sum is 2; right subtree is just right child, so sum is 3)
28+
Sum of every tilt : 0 + 0 + 1 = 1
29+
</pre>
30+
31+
<p><strong>Example 2:</strong></p>
32+
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/20/tilt2.jpg" style="width: 800px; height: 203px;" />
33+
<pre>
34+
<strong>Input:</strong> root = [4,2,9,3,5,null,7]
35+
<strong>Output:</strong> 15
36+
<strong>Explanation:</strong>
37+
Tilt of node 3 : |0-0| = 0 (no children)
38+
Tilt of node 5 : |0-0| = 0 (no children)
39+
Tilt of node 7 : |0-0| = 0 (no children)
40+
Tilt of node 2 : |3-5| = 2 (left subtree is just left child, so sum is 3; right subtree is just right child, so sum is 5)
41+
Tilt of node 9 : |0-7| = 7 (no left child, so sum is 0; right subtree is just right child, so sum is 7)
42+
Tilt of node 4 : |(3+5+2)-(9+7)| = |10-16| = 6 (left subtree values are 3, 5, and 2, which sums to 10; right subtree values are 9 and 7, which sums to 16)
43+
Sum of every tilt : 0 + 0 + 0 + 2 + 7 + 6 = 15
44+
</pre>
1945

20-
<p><b>Example:</b><br />
46+
<p><strong>Example 3:</strong></p>
47+
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/20/tilt3.jpg" style="width: 800px; height: 293px;" />
2148
<pre>
22-
<b>Input:</b>
23-
1
24-
/ \
25-
2 3
26-
<b>Output:</b> 1
27-
<b>Explanation:</b>
28-
Tilt of node 2 : 0
29-
Tilt of node 3 : 0
30-
Tilt of node 1 : |2-3| = 1
31-
Tilt of binary tree : 0 + 0 + 1 = 1
49+
<strong>Input:</strong> root = [21,7,14,1,1,2,2,3,3]
50+
<strong>Output:</strong> 9
3251
</pre>
33-
</p>
3452

35-
<p><b>Note:</b>
36-
<ol>
37-
<li>The sum of node values in any subtree won't exceed the range of 32-bit integer. </li>
38-
<li>All the tilt values won't exceed the range of 32-bit integer.</li>
39-
</ol>
40-
</p>
53+
<p>&nbsp;</p>
54+
<p><strong>Constraints:</strong></p>
55+
56+
<ul>
57+
<li>The number of nodes in the tree is in the range <code>[0, 10<sup>4</sup>]</code>.</li>
58+
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
59+
</ul>
4160

4261
### Related Topics
4362
[[Tree](../../tag/tree/README.md)]

problems/champagne-tower/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
## [799. Champagne Tower (Medium)](https://leetcode.com/problems/champagne-tower "香槟塔")
1313

14-
<p>We stack glasses in a pyramid, where the <strong>first</strong> row has <code>1</code> glass, the <strong>second</strong> row has <code>2</code> glasses, and so on until the 100<sup>th</sup> row.&nbsp; Each glass holds one cup (<code>250</code>ml) of champagne.</p>
14+
<p>We stack glasses in a pyramid, where the <strong>first</strong> row has <code>1</code> glass, the <strong>second</strong> row has <code>2</code> glasses, and so on until the 100<sup>th</sup> row.&nbsp; Each glass holds one cup&nbsp;of champagne.</p>
1515

16-
<p>Then, some champagne is poured in the first glass at the top.&nbsp; When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.&nbsp; When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.&nbsp; (A glass at the bottom row has its excess champagne fall on the floor.)</p>
16+
<p>Then, some champagne is poured into the first glass at the top.&nbsp; When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it.&nbsp; When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on.&nbsp; (A glass at the bottom row has its excess champagne fall on the floor.)</p>
1717

1818
<p>For example, after one cup of champagne is poured, the top most glass is full.&nbsp; After two cups of champagne are poured, the two glasses on the second row are half full.&nbsp; After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now.&nbsp; After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.</p>
1919

@@ -52,3 +52,6 @@
5252
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
5353
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
5454
</ul>
55+
56+
### Related Topics
57+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]

0 commit comments

Comments
 (0)