Skip to content

Commit 4016ed7

Browse files
author
openset
committed
Add: new
1 parent 6724d5b commit 4016ed7

File tree

37 files changed

+576
-51
lines changed

37 files changed

+576
-51
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1250">1250</span> | [Check If It Is a Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array "检查「好数组」") | [Go](https://github.com/openset/leetcode/tree/master/problems/check-if-it-is-a-good-array) | Hard |
66+
| <span id="1249">1249</span> | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses "移除无效的括号") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-remove-to-make-valid-parentheses) | Medium |
67+
| <span id="1248">1248</span> | [Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays "统计「优美子数组」") | [Go](https://github.com/openset/leetcode/tree/master/problems/count-number-of-nice-subarrays) | Medium |
68+
| <span id="1247">1247</span> | [Minimum Swaps to Make Strings Equal](https://leetcode.com/problems/minimum-swaps-to-make-strings-equal "交换字符使得字符串相同") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-make-strings-equal) | Medium |
69+
| <span id="1246">1246</span> | [Palindrome Removal](https://leetcode.com/problems/palindrome-removal "删除回文子数组") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/palindrome-removal) | Hard |
70+
| <span id="1245">1245</span> | [Tree Diameter](https://leetcode.com/problems/tree-diameter "树的直径") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/tree-diameter) | Medium |
71+
| <span id="1244">1244</span> | [Design A Leaderboard](https://leetcode.com/problems/design-a-leaderboard "力扣排行榜") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-a-leaderboard) | Medium |
72+
| <span id="1243">1243</span> | [Array Transformation](https://leetcode.com/problems/array-transformation "数组变换") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/array-transformation) | Easy |
73+
| <span id="1242">1242</span> | [Web Crawler Multithreaded](https://leetcode.com/problems/web-crawler-multithreaded) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/web-crawler-multithreaded) | Medium |
74+
| <span id="1241">1241</span> | [Number of Comments per Post](https://leetcode.com/problems/number-of-comments-per-post "每个帖子的评论数") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/number-of-comments-per-post) | Easy |
6575
| <span id="1240">1240</span> | [Tiling a Rectangle with the Fewest Squares](https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares "铺瓷砖") | [Go](https://github.com/openset/leetcode/tree/master/problems/tiling-a-rectangle-with-the-fewest-squares) | Hard |
6676
| <span id="1239">1239</span> | [Maximum Length of a Concatenated String with Unique Characters](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters "串联字符串的最大长度") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-length-of-a-concatenated-string-with-unique-characters) | Medium |
6777
| <span id="1238">1238</span> | [Circular Permutation in Binary Representation](https://leetcode.com/problems/circular-permutation-in-binary-representation "循环码排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/circular-permutation-in-binary-representation) | Medium |
@@ -154,7 +164,7 @@ LeetCode Problems' Solutions
154164
| <span id="1151">1151</span> | [Minimum Swaps to Group All 1's Together](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together "最少交换次数来组合所有的 1") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-group-all-1s-together) | Medium |
155165
| <span id="1150">1150</span> | [Check If a Number Is Majority Element in a Sorted Array](https://leetcode.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array "检查一个数是否在数组中占绝大多数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/check-if-a-number-is-majority-element-in-a-sorted-array) | Easy |
156166
| <span id="1149">1149</span> | [Article Views II](https://leetcode.com/problems/article-views-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/article-views-ii) | Medium |
157-
| <span id="1148">1148</span> | [Article Views I](https://leetcode.com/problems/article-views-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/article-views-i) | Easy |
167+
| <span id="1148">1148</span> | [Article Views I](https://leetcode.com/problems/article-views-i "文章浏览 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/article-views-i) | Easy |
158168
| <span id="1147">1147</span> | [Longest Chunked Palindrome Decomposition](https://leetcode.com/problems/longest-chunked-palindrome-decomposition "段式回文") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-chunked-palindrome-decomposition) | Hard |
159169
| <span id="1146">1146</span> | [Snapshot Array](https://leetcode.com/problems/snapshot-array "快照数组") | [Go](https://github.com/openset/leetcode/tree/master/problems/snapshot-array) | Medium |
160170
| <span id="1145">1145</span> | [Binary Tree Coloring Game](https://leetcode.com/problems/binary-tree-coloring-game "二叉树着色游戏") | [Go](https://github.com/openset/leetcode/tree/master/problems/binary-tree-coloring-game) | Medium |
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](https://github.com/openset/leetcode/tree/master/problems/web-crawler-multithreaded "Web Crawler Multithreaded")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/design-a-leaderboard "Design A Leaderboard")
11+
12+
## [1243. Array Transformation (Easy)](https://leetcode.com/problems/array-transformation "数组变换")
13+
14+
15+
16+
### Related Topics
17+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
18+
19+
### Hints
20+
<details>
21+
<summary>Hint 1</summary>
22+
Try to simulate the process.
23+
</details>
24+
25+
<details>
26+
<summary>Hint 2</summary>
27+
For every iteration, find the new array using the old one and the given rules.
28+
</details>

problems/article-views-i/README.md

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

1010
[Next >](https://github.com/openset/leetcode/tree/master/problems/article-views-ii "Article Views II")
1111

12-
## [1148. Article Views I (Easy)](https://leetcode.com/problems/article-views-i "")
12+
## [1148. Article Views I (Easy)](https://leetcode.com/problems/article-views-i "文章浏览 I")
1313

1414

problems/binary-tree-level-order-traversal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ return its level order traversal as:<br />
4545
1. [Minimum Depth of Binary Tree](https://github.com/openset/leetcode/tree/master/problems/minimum-depth-of-binary-tree) (Easy)
4646
1. [Binary Tree Vertical Order Traversal](https://github.com/openset/leetcode/tree/master/problems/binary-tree-vertical-order-traversal) (Medium)
4747
1. [Average of Levels in Binary Tree](https://github.com/openset/leetcode/tree/master/problems/average-of-levels-in-binary-tree) (Easy)
48-
1. [N-ary Tree Level Order Traversal](https://github.com/openset/leetcode/tree/master/problems/n-ary-tree-level-order-traversal) (Easy)
48+
1. [N-ary Tree Level Order Traversal](https://github.com/openset/leetcode/tree/master/problems/n-ary-tree-level-order-traversal) (Medium)
4949
1. [Cousins in Binary Tree](https://github.com/openset/leetcode/tree/master/problems/cousins-in-binary-tree) (Easy)
Lines changed: 64 additions & 0 deletions
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 <openset.wang@gmail.com> |-->
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/minimum-remove-to-make-valid-parentheses "Minimum Remove to Make Valid Parentheses")
9+
                
10+
Next >
11+
12+
## [1250. Check If It Is a Good Array (Hard)](https://leetcode.com/problems/check-if-it-is-a-good-array "检查「好数组」")
13+
14+
<p>Given an array <code>nums</code> of&nbsp;positive integers. Your task is to select some subset of <code>nums</code>, multiply each element by an integer and add all these numbers.&nbsp;The array is said to be&nbsp;<strong>good&nbsp;</strong>if you can obtain a sum of&nbsp;<code>1</code>&nbsp;from the array by any possible subset and multiplicand.</p>
15+
16+
<p>Return&nbsp;<code>True</code>&nbsp;if the array is <strong>good&nbsp;</strong>otherwise&nbsp;return&nbsp;<code>False</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [12,5,7,23]
23+
<strong>Output:</strong> true
24+
<strong>Explanation:</strong> Pick numbers 5 and 7.
25+
5*3 + 7*(-2) = 1
26+
</pre>
27+
28+
<p><strong>Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> nums = [29,6,10]
32+
<strong>Output:</strong> true
33+
<strong>Explanation:</strong> Pick numbers 29, 6 and 10.
34+
29*1 + 6*(-3) + 10*(-1) = 1
35+
</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> nums = [3,6]
41+
<strong>Output:</strong> false
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
49+
<li><code>1 &lt;= nums[i] &lt;= 10^9</code></li>
50+
</ul>
51+
52+
### Related Topics
53+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
54+
55+
### Hints
56+
<details>
57+
<summary>Hint 1</summary>
58+
Eq. ax+by=1 has solution x, y if gcd(a,b) = 1.
59+
</details>
60+
61+
<details>
62+
<summary>Hint 2</summary>
63+
Can you generalize the formula?. Check Bézout's lemma.
64+
</details>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-make-strings-equal "Minimum Swaps to Make Strings Equal")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-remove-to-make-valid-parentheses "Minimum Remove to Make Valid Parentheses")
11+
12+
## [1248. Count Number of Nice Subarrays (Medium)](https://leetcode.com/problems/count-number-of-nice-subarrays "统计「优美子数组」")
13+
14+
<p>Given an array of integers <code>nums</code> and an integer&nbsp;<code>k</code>. A<em>&nbsp;</em>subarray&nbsp;is called <strong>nice</strong>&nbsp;if there are&nbsp;<code>k</code> odd numbers on it.</p>
15+
16+
<p>Return the number of <strong>nice</strong> sub-arrays.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [1,1,2,1,1], k = 3
23+
<strong>Output:</strong> 2
24+
<strong>Explanation:</strong> The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> nums = [2,4,6], k = 1
31+
<strong>Output:</strong> 0
32+
<strong>Explanation:</strong> There is no odd numbers in the array.
33+
</pre>
34+
35+
<p><strong>Example 3:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> nums = [2,2,2,1,2,2,1,2,2,2], k = 2
39+
<strong>Output:</strong> 16
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= nums.length &lt;= 50000</code></li>
47+
<li><code>1 &lt;= nums[i] &lt;= 10^5</code></li>
48+
<li><code>1 &lt;= k &lt;= nums.length</code></li>
49+
</ul>
50+
51+
### Related Topics
52+
[[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)]
53+
54+
### Hints
55+
<details>
56+
<summary>Hint 1</summary>
57+
After replacing each even by zero and every odd by one can we use prefix sum to find answer ?
58+
</details>
59+
60+
<details>
61+
<summary>Hint 2</summary>
62+
Can we use two pointers to count number of sub-arrays ?
63+
</details>
64+
65+
<details>
66+
<summary>Hint 3</summary>
67+
Can we store indices of odd numbers and for each k indices count number of sub-arrays contains them ?
68+
</details>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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](https://github.com/openset/leetcode/tree/master/problems/array-transformation "Array Transformation")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/tree-diameter "Tree Diameter")
11+
12+
## [1244. Design A Leaderboard (Medium)](https://leetcode.com/problems/design-a-leaderboard "力扣排行榜")
13+
14+
15+
16+
### Related Topics
17+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
18+
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]
19+
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
20+
21+
### Hints
22+
<details>
23+
<summary>Hint 1</summary>
24+
What data structure can we use to keep the players' data?
25+
</details>
26+
27+
<details>
28+
<summary>Hint 2</summary>
29+
Keep a map (dictionary) of player scores.
30+
</details>
31+
32+
<details>
33+
<summary>Hint 3</summary>
34+
For each top(K) function call, find the maximum K scores and add them.
35+
</details>

problems/design-linked-list/README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@
1616
<p>Implement these functions in your linked list class:</p>
1717

1818
<ul>
19-
<li>get(index) : Get the value of&nbsp;the <code>index</code>-th&nbsp;node in the linked list. If the index is invalid, return <code>-1</code>.</li>
20-
<li>addAtHead(val) : Add a node of value <code>val</code>&nbsp;before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.</li>
21-
<li>addAtTail(val) : Append a node of value <code>val</code>&nbsp;to the last element of the linked list.</li>
22-
<li>addAtIndex(index, val) : Add a node of value <code>val</code>&nbsp;before the <code>index</code>-th&nbsp;node in the linked list.&nbsp;If <code>index</code>&nbsp;equals&nbsp;to the length of&nbsp;linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. If index is negative, the node will be inserted at the head&nbsp;of the list.</li>
23-
<li>deleteAtIndex(index) : Delete&nbsp;the <code>index</code>-th&nbsp;node in the linked list, if the index is valid.</li>
19+
<li><code>get(index)</code> : Get the value of&nbsp;the <code>index</code>-th&nbsp;node in the linked list. If the index is invalid, return <code>-1</code>.</li>
20+
<li><code>addAtHead(val)</code> : Add a node of value <code>val</code>&nbsp;before the first element of the linked list. After the insertion, the new node will be the first node of the linked list.</li>
21+
<li><code>addAtTail(val)</code> : Append a node of value <code>val</code>&nbsp;to the last element of the linked list.</li>
22+
<li><code>addAtIndex(index, val)</code> : Add a node of value <code>val</code>&nbsp;before the <code>index</code>-th&nbsp;node in the linked list.&nbsp;If <code>index</code>&nbsp;equals&nbsp;to the length of&nbsp;linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted.</li>
23+
<li><code>deleteAtIndex(index)</code> : Delete&nbsp;the <code>index</code>-th&nbsp;node in the linked list, if the index is valid.</li>
2424
</ul>
2525

26+
<p>&nbsp;</p>
27+
2628
<p><strong>Example:</strong></p>
2729

2830
<pre>
29-
MyLinkedList linkedList = new MyLinkedList();
31+
<b>Input: </b>
32+
[&quot;MyLinkedList&quot;,&quot;addAtHead&quot;,&quot;addAtTail&quot;,&quot;addAtIndex&quot;,&quot;get&quot;,&quot;deleteAtIndex&quot;,&quot;get&quot;]
33+
[[],[1],[3],[1,2],[1],[1],[1]]
34+
<b>Output: </b>
35+
[null,null,null,null,2,null,3]
36+
37+
<b>Explanation:</b>
38+
MyLinkedList linkedList = new MyLinkedList(); // Initialize empty LinkedList
3039
linkedList.addAtHead(1);
3140
linkedList.addAtTail(3);
3241
linkedList.addAtIndex(1, 2); // linked list becomes 1-&gt;2-&gt;3
@@ -35,12 +44,13 @@ linkedList.deleteAtIndex(1); // now the linked list is 1-&gt;3
3544
linkedList.get(1);&nbsp;&nbsp;&nbsp; // returns 3
3645
</pre>
3746

38-
<p><strong>Note:</strong></p>
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
3949

4050
<ul>
41-
<li>All values will be in the range of <code>[1, 1000]</code>.</li>
42-
<li>The number of operations will be in the range of&nbsp;<code>[1, 1000]</code>.</li>
51+
<li><code>0 &lt;= index,val &lt;= 1000</code></li>
4352
<li>Please do not use the built-in LinkedList library.</li>
53+
<li>At most <code>2000</code>&nbsp;calls will be made to&nbsp;<code>get</code>,&nbsp;<code>addAtHead</code>,&nbsp;<code>addAtTail</code>,&nbsp; <code>addAtIndex</code> and&nbsp;<code>deleteAtIndex</code>.</li>
4454
</ul>
4555

4656
### Related Topics

0 commit comments

Comments
 (0)