Skip to content

Commit 4b2ab79

Browse files
author
Shuo
committed
A: new
1 parent a0dbe9a commit 4b2ab79

File tree

18 files changed

+342
-27
lines changed

18 files changed

+342
-27
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1499">1499</span> | [Max Value of Equation](https://leetcode.com/problems/max-value-of-equation "满足不等式的最大值") | [Go](problems/max-value-of-equation) | Hard |
66+
| <span id="1498">1498</span> | [Number of Subsequences That Satisfy the Given Sum Condition](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition "满足条件的子序列数目") | [Go](problems/number-of-subsequences-that-satisfy-the-given-sum-condition) | Medium |
67+
| <span id="1497">1497</span> | [Check If Array Pairs Are Divisible by k](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k "检查数组对是否可以被 k 整除") | [Go](problems/check-if-array-pairs-are-divisible-by-k) | Medium |
68+
| <span id="1496">1496</span> | [Path Crossing](https://leetcode.com/problems/path-crossing "判断路径是否相交") | [Go](problems/path-crossing) | Easy |
6569
| <span id="1495">1495</span> | [Friendly Movies Streamed Last Month](https://leetcode.com/problems/friendly-movies-streamed-last-month) 🔒 | [MySQL](problems/friendly-movies-streamed-last-month) | Easy |
6670
| <span id="1494">1494</span> | [Parallel Courses II](https://leetcode.com/problems/parallel-courses-ii "并行课程 II") | [Go](problems/parallel-courses-ii) | Hard |
6771
| <span id="1493">1493</span> | [Longest Subarray of 1's After Deleting One Element](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element "删掉一个元素以后全为 1 的最长子数组") | [Go](problems/longest-subarray-of-1s-after-deleting-one-element) | Medium |

problems/arithmetic-slices/README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@
1111

1212
## [413. Arithmetic Slices (Medium)](https://leetcode.com/problems/arithmetic-slices "等差数列划分")
1313

14-
<p>A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.</p>
14+
<p>A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.</p>
1515

16-
<p>For example, these are arithmetic sequence:</p>
17-
<pre>1, 3, 5, 7, 9
16+
<p>For example, these are arithmetic sequences:</p>
17+
18+
<pre>
19+
1, 3, 5, 7, 9
1820
7, 7, 7, 7
1921
3, -1, -5, -9</pre>
2022

21-
<p>The following sequence is not arithmetic.</p> <pre>1, 1, 2, 5, 7</pre>
22-
<br/>
23+
<p>The following sequence is not arithmetic.</p>
24+
25+
<pre>
26+
1, 1, 2, 5, 7</pre>
27+
&nbsp;
28+
29+
<p>A zero-indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 &lt;= P &lt; Q &lt; N.</p>
2330

24-
<p>A zero-indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 <= P < Q < N.</p>
31+
<p>A slice (P, Q) of the array A is called arithmetic if the sequence:<br />
32+
A[P], A[P&nbsp;+ 1], ..., A[Q - 1], A[Q] is arithmetic. In particular, this means that P + 1 &lt; Q.</p>
2533

26-
<p>A slice (P, Q) of array A is called arithmetic if the sequence:<br/>
27-
A[P], A[p + 1], ..., A[Q - 1], A[Q] is arithmetic. In particular, this means that P + 1 < Q.</p>
34+
<p>The function should return the number of arithmetic slices in the array A.</p>
35+
&nbsp;
2836

29-
<p>The function should return the number of arithmetic slices in the array A. </p>
30-
<br/>
37+
<p><b>Example:</b></p>
3138

32-
<p><b>Example:</b>
3339
<pre>
3440
A = [1, 2, 3, 4]
3541

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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](../path-crossing "Path Crossing")
9+
                
10+
[Next >](../number-of-subsequences-that-satisfy-the-given-sum-condition "Number of Subsequences That Satisfy the Given Sum Condition")
11+
12+
## [1497. Check If Array Pairs Are Divisible by k (Medium)](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k "检查数组对是否可以被 k 整除")
13+
14+
<p>Given an array of integers <code>arr</code> of even length <code>n</code> and an integer <code>k</code>.</p>
15+
16+
<p>We want to divide the array into exactly <code>n /&nbsp;2</code> pairs such that the sum of each pair is divisible by <code>k</code>.</p>
17+
18+
<p>Return <em>True</em> If you can find a way to do that or <em>False</em> otherwise.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> arr = [1,2,3,4,5,10,6,7,8,9], k = 5
25+
<strong>Output:</strong> true
26+
<strong>Explanation:</strong> Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).
27+
</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> arr = [1,2,3,4,5,6], k = 7
33+
<strong>Output:</strong> true
34+
<strong>Explanation:</strong> Pairs are (1,6),(2,5) and(3,4).
35+
</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> arr = [1,2,3,4,5,6], k = 10
41+
<strong>Output:</strong> false
42+
<strong>Explanation:</strong> You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.
43+
</pre>
44+
45+
<p><strong>Example 4:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> arr = [-10,10], k = 2
49+
<strong>Output:</strong> true
50+
</pre>
51+
52+
<p><strong>Example 5:</strong></p>
53+
54+
<pre>
55+
<strong>Input:</strong> arr = [-1,1,-2,2,-3,3,-4,4], k = 3
56+
<strong>Output:</strong> true
57+
</pre>
58+
59+
<p>&nbsp;</p>
60+
<p><strong>Constraints:</strong></p>
61+
62+
<ul>
63+
<li><code>arr.length == n</code></li>
64+
<li><code>1 &lt;= n &lt;= 10^5</code></li>
65+
<li><code>n</code> is even.</li>
66+
<li><code>-10^9 &lt;= arr[i] &lt;= 10^9</code></li>
67+
<li><code>1 &lt;= k &lt;= 10^5</code></li>
68+
</ul>
69+
70+
### Related Topics
71+
[[Greedy](../../tag/greedy/README.md)]
72+
[[Array](../../tag/array/README.md)]
73+
[[Math](../../tag/math/README.md)]
74+
75+
### Hints
76+
<details>
77+
<summary>Hint 1</summary>
78+
Keep an array of the frequencies of ((x % k) + k) % k for each x in arr.
79+
</details>
80+
81+
<details>
82+
<summary>Hint 2</summary>
83+
for each i in [0, k - 1] we need to check if freq[k] == freq[k - i]
84+
</details>
85+
86+
<details>
87+
<summary>Hint 3</summary>
88+
Take care of the case when i == k - i and when i == 0
89+
</details>

problems/expressive-words/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ We can&#39;t extend &quot;helo&quot; to get &quot;heeellooo&quot; because the gr
3333
</pre>
3434

3535
<p>&nbsp;</p>
36-
37-
<p><strong>Notes: </strong></p>
36+
<p><strong>Constraints:</strong></p>
3837

3938
<ul>
4039
<li><code>0 &lt;= len(S) &lt;= 100</code>.</li>
@@ -43,7 +42,5 @@ We can&#39;t extend &quot;helo&quot; to get &quot;heeellooo&quot; because the gr
4342
<li><code>S</code> and all words in <code>words</code>&nbsp;consist only of&nbsp;lowercase letters</li>
4443
</ul>
4544

46-
<p>&nbsp;</p>
47-
4845
### Related Topics
4946
[[String](../../tag/string/README.md)]

problems/friendly-movies-streamed-last-month/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](../parallel-courses-ii "Parallel Courses II")
99

10-
Next >
10+
[Next >](../path-crossing "Path Crossing")
1111

1212
## [1495. Friendly Movies Streamed Last Month (Easy)](https://leetcode.com/problems/friendly-movies-streamed-last-month "")
1313

problems/intersection-of-two-linked-lists/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
<p>&nbsp;</p>
2222

2323
<p><strong>Example 1:</strong></p>
24-
<a href="https://assets.leetcode.com/uploads/2018/12/13/160_example_1.png" target="_blank"><img alt="" src="https://assets.leetcode.com/uploads/2018/12/13/160_example_1.png" style="margin-top: 10px; margin-bottom: 10px; width: 400px; height: 130px;" /></a>
24+
<a href="https://assets.leetcode.com/uploads/2020/06/29/160_example_1_1.png" target="_blank"><img alt="" src="https://assets.leetcode.com/uploads/2020/06/29/160_example_1_1.png" style="margin-top: 10px; margin-bottom: 10px; width: 400px; height: 130px;" /></a>
2525

2626
<pre>
27-
<strong>Input: </strong>intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
27+
<strong>Input: </strong>intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3
2828
<strong>Output:</strong> Reference of the node with value = 8
29-
<strong>Input Explanation:</strong> The intersected node&#39;s value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,0,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.</pre>
29+
<strong>Input Explanation:</strong> The intersected node&#39;s value is 8 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [4,1,8,4,5]. From the head of B, it reads as [5,6,1,8,4,5]. There are 2 nodes before the intersected node in A; There are 3 nodes before the intersected node in B.</pre>
3030

3131
<p>&nbsp;</p>
3232

3333
<p><strong>Example 2:</strong></p>
34-
<a href="https://assets.leetcode.com/uploads/2018/12/13/160_example_2.png" target="_blank"><img alt="" src="https://assets.leetcode.com/uploads/2018/12/13/160_example_2.png" style="margin-top: 10px; margin-bottom: 10px; width: 350px; height: 136px;" /></a>
34+
<a href="https://assets.leetcode.com/uploads/2020/06/29/160_example_2.png" target="_blank"><img alt="" src="https://assets.leetcode.com/uploads/2020/06/29/160_example_2.png" style="margin-top: 10px; margin-bottom: 10px; width: 350px; height: 136px;" /></a>
3535

3636
<pre>
37-
<strong>Input: </strong>intersectVal&nbsp;= 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
37+
<strong>Input: </strong>intersectVal&nbsp;= 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
3838
<strong>Output:</strong> Reference of the node with value = 2
39-
<strong>Input Explanation:</strong>&nbsp;The intersected node&#39;s value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [0,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.
39+
<strong>Input Explanation:</strong>&nbsp;The intersected node&#39;s value is 2 (note that this must not be 0 if the two lists intersect). From the head of A, it reads as [1,9,1,2,4]. From the head of B, it reads as [3,2,4]. There are 3 nodes before the intersected node in A; There are 1 node before the intersected node in B.
4040
</pre>
4141

4242
<p>&nbsp;</p>
@@ -59,6 +59,7 @@
5959
<li>If the two linked lists have no intersection at all, return <code>null</code>.</li>
6060
<li>The linked lists must retain their original structure after the function returns.</li>
6161
<li>You may assume there are no cycles anywhere in the entire linked structure.</li>
62+
<li>Each value&nbsp;on each linked list is in the range <code>[1, 10^9]</code>.</li>
6263
<li>Your code should preferably run in O(n) time and use only O(1) memory.</li>
6364
</ul>
6465

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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-subsequences-that-satisfy-the-given-sum-condition "Number of Subsequences That Satisfy the Given Sum Condition")
9+
                
10+
Next >
11+
12+
## [1499. Max Value of Equation (Hard)](https://leetcode.com/problems/max-value-of-equation "满足不等式的最大值")
13+
14+
<p>Given an&nbsp;array <code>points</code> containing the coordinates of points on a 2D plane,&nbsp;sorted by the x-values, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;such that&nbsp;<code>x<sub>i</sub> &lt; x<sub>j</sub></code> for all <code>1 &lt;= i &lt; j &lt;= points.length</code>. You are also given an integer&nbsp;<code>k</code>.</p>
15+
16+
<p>Find the <em>maximum value of the equation </em><code>y<sub>i</sub>&nbsp;+ y<sub>j</sub>&nbsp;+ |x<sub>i</sub>&nbsp;- x<sub>j</sub>|</code>&nbsp;where <code>|x<sub>i</sub>&nbsp;- x<sub>j</sub>|&nbsp;&lt;= k</code>&nbsp;and <code>1 &lt;= i &lt; j &lt;= points.length</code>. It is guaranteed that there exists at least one pair of points that satisfy the constraint <code>|x<sub>i</sub>&nbsp;- x<sub>j</sub>|&nbsp;&lt;= k</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> points = [[1,3],[2,0],[5,10],[6,-10]], k = 1
23+
<strong>Output:</strong> 4
24+
<strong>Explanation:</strong> The first two points satisfy the condition |x<sub>i</sub>&nbsp;- x<sub>j</sub>| &lt;= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.
25+
No other pairs satisfy the condition, so we return the max of 4 and 1.</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> points = [[0,0],[3,0],[9,2]], k = 3
31+
<strong>Output:</strong> 3
32+
<strong>Explanation: </strong>Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3.
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>2 &lt;= points.length &lt;= 10^5</code></li>
40+
<li><code>points[i].length == 2</code></li>
41+
<li><code>-10^8&nbsp;&lt;= points[i][0], points[i][1] &lt;= 10^8</code></li>
42+
<li><code>0 &lt;= k &lt;= 2 * 10^8</code></li>
43+
<li><code>points[i][0] &lt; points[j][0]</code>&nbsp;for all&nbsp;<code>1 &lt;= i &lt; j &lt;= points.length</code></li>
44+
<li><code>x<sub>i</sub></code>&nbsp;form a strictly increasing sequence.</li>
45+
</ul>
46+
47+
### Related Topics
48+
[[Array](../../tag/array/README.md)]
49+
[[Sliding Window](../../tag/sliding-window/README.md)]
50+
51+
### Hints
52+
<details>
53+
<summary>Hint 1</summary>
54+
Use a priority queue to store for each point i, the tuple [yi-xi, xi]
55+
</details>
56+
57+
<details>
58+
<summary>Hint 2</summary>
59+
Loop through the array and pop elements from the heap if the condition xj - xi > k, where j is the current index and i is the point on top the queue.
60+
</details>
61+
62+
<details>
63+
<summary>Hint 3</summary>
64+
After popping elements from the queue. If the queue is not empty, calculate the equation with the current point and the point on top of the queue and maximize the answer.
65+
</details>

problems/maximum-length-of-repeated-subarray/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ The repeated subarray with maximum length is [3, 2, 1].
4747
### Hints
4848
<details>
4949
<summary>Hint 1</summary>
50-
Use dynamic programming. dp[i][j] will be the answer for inputs A[i:], B[j:].
50+
运用动态规划的方法,dp[i][j] 就是是输入中 A [i:], B[j:] 所对应的答案。
5151
</details>

problems/merge-sorted-array/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<ul>
1919
<li>The number of elements initialized in <em>nums1</em> and <em>nums2</em> are <em>m</em> and <em>n</em> respectively.</li>
20-
<li>You may assume that <em>nums1</em> has enough space (size that is greater or equal to <em>m</em> + <em>n</em>) to hold additional elements from <em>nums2</em>.</li>
20+
<li>You may assume that <em>nums1</em> has enough space (size that is&nbsp;<strong>equal</strong> to <em>m</em> + <em>n</em>) to hold additional elements from <em>nums2</em>.</li>
2121
</ul>
2222

2323
<p><strong>Example:</strong></p>
@@ -35,6 +35,8 @@ nums2 = [2,5,6], n = 3
3535

3636
<ul>
3737
<li><code>-10^9 &lt;= nums1[i], nums2[i] &lt;= 10^9</code></li>
38+
<li><code>nums1.length == m + n</code></li>
39+
<li><code>nums2.length == n</code></li>
3840
</ul>
3941

4042
### Related Topics

problems/n-repeated-element-in-size-2n-array/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## [961. N-Repeated Element in Size 2N Array (Easy)](https://leetcode.com/problems/n-repeated-element-in-size-2n-array "重复 N 次的元素")
1313

14-
<p>In a array <code>A</code> of size <code>2N</code>, there are <code>N+1</code> unique elements, and exactly one of these elements is repeated N times.</p>
14+
<p>In a array <code>A</code> of size <code>2N</code>, there are <code>N+1</code> unique elements, and exactly one of these elements is repeated <code>N</code> times.</p>
1515

1616
<p>Return the element repeated <code>N</code> times.</p>
1717

@@ -48,11 +48,11 @@
4848

4949
<p><strong>Note:</strong></p>
5050

51-
<ol>
51+
<ul>
5252
<li><code>4 &lt;= A.length &lt;= 10000</code></li>
5353
<li><code>0 &lt;= A[i] &lt; 10000</code></li>
5454
<li><code>A.length</code> is even</li>
55-
</ol>
55+
</ul>
5656
</div>
5757
</div>
5858
</div>

0 commit comments

Comments
 (0)