Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down Expand Up @@ -154,7 +164,7 @@ LeetCode Problems' Solutions
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
28 changes: 28 additions & 0 deletions problems/array-transformation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/web-crawler-multithreaded "Web Crawler Multithreaded")

[Next >](https://github.com/openset/leetcode/tree/master/problems/design-a-leaderboard "Design A Leaderboard")

## [1243. Array Transformation (Easy)](https://leetcode.com/problems/array-transformation "数组变换")



### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Try to simulate the process.
</details>

<details>
<summary>Hint 2</summary>
For every iteration, find the new array using the old one and the given rules.
</details>
2 changes: 1 addition & 1 deletion problems/article-views-i/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

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

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


2 changes: 1 addition & 1 deletion problems/binary-tree-level-order-traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ return its level order traversal as:<br />
1. [Minimum Depth of Binary Tree](https://github.com/openset/leetcode/tree/master/problems/minimum-depth-of-binary-tree) (Easy)
1. [Binary Tree Vertical Order Traversal](https://github.com/openset/leetcode/tree/master/problems/binary-tree-vertical-order-traversal) (Medium)
1. [Average of Levels in Binary Tree](https://github.com/openset/leetcode/tree/master/problems/average-of-levels-in-binary-tree) (Easy)
1. [N-ary Tree Level Order Traversal](https://github.com/openset/leetcode/tree/master/problems/n-ary-tree-level-order-traversal) (Easy)
1. [N-ary Tree Level Order Traversal](https://github.com/openset/leetcode/tree/master/problems/n-ary-tree-level-order-traversal) (Medium)
1. [Cousins in Binary Tree](https://github.com/openset/leetcode/tree/master/problems/cousins-in-binary-tree) (Easy)
64 changes: 64 additions & 0 deletions problems/check-if-it-is-a-good-array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-remove-to-make-valid-parentheses "Minimum Remove to Make Valid Parentheses")

Next >

## [1250. Check If It Is a Good Array (Hard)](https://leetcode.com/problems/check-if-it-is-a-good-array "检查「好数组」")

<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>

<p>Return&nbsp;<code>True</code>&nbsp;if the array is <strong>good&nbsp;</strong>otherwise&nbsp;return&nbsp;<code>False</code>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [12,5,7,23]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 5 and 7.
5*3 + 7*(-2) = 1
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [29,6,10]
<strong>Output:</strong> true
<strong>Explanation:</strong> Pick numbers 29, 6 and 10.
29*1 + 6*(-3) + 10*(-1) = 1
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,6]
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10^9</code></li>
</ul>

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Eq. ax+by=1 has solution x, y if gcd(a,b) = 1.
</details>

<details>
<summary>Hint 2</summary>
Can you generalize the formula?. Check Bézout's lemma.
</details>
68 changes: 68 additions & 0 deletions problems/count-number-of-nice-subarrays/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-swaps-to-make-strings-equal "Minimum Swaps to Make Strings Equal")

[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-remove-to-make-valid-parentheses "Minimum Remove to Make Valid Parentheses")

## [1248. Count Number of Nice Subarrays (Medium)](https://leetcode.com/problems/count-number-of-nice-subarrays "统计「优美子数组」")

<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>

<p>Return the number of <strong>nice</strong> sub-arrays.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,1,2,1,1], k = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,4,6], k = 1
<strong>Output:</strong> 0
<strong>Explanation:</strong> There is no odd numbers in the array.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,2,2,1,2,2,1,2,2,2], k = 2
<strong>Output:</strong> 16
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= nums.length &lt;= 50000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 10^5</code></li>
<li><code>1 &lt;= k &lt;= nums.length</code></li>
</ul>

### Related Topics
[[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
After replacing each even by zero and every odd by one can we use prefix sum to find answer ?
</details>

<details>
<summary>Hint 2</summary>
Can we use two pointers to count number of sub-arrays ?
</details>

<details>
<summary>Hint 3</summary>
Can we store indices of odd numbers and for each k indices count number of sub-arrays contains them ?
</details>
35 changes: 35 additions & 0 deletions problems/design-a-leaderboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/array-transformation "Array Transformation")

[Next >](https://github.com/openset/leetcode/tree/master/problems/tree-diameter "Tree Diameter")

## [1244. Design A Leaderboard (Medium)](https://leetcode.com/problems/design-a-leaderboard "力扣排行榜")



### Related Topics
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
[[Design](https://github.com/openset/leetcode/tree/master/tag/design/README.md)]
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
What data structure can we use to keep the players' data?
</details>

<details>
<summary>Hint 2</summary>
Keep a map (dictionary) of player scores.
</details>

<details>
<summary>Hint 3</summary>
For each top(K) function call, find the maximum K scores and add them.
</details>
28 changes: 19 additions & 9 deletions problems/design-linked-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@
<p>Implement these functions in your linked list class:</p>

<ul>
<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>
<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>
<li>addAtTail(val) : Append a node of value <code>val</code>&nbsp;to the last element of the linked list.</li>
<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>
<li>deleteAtIndex(index) : Delete&nbsp;the <code>index</code>-th&nbsp;node in the linked list, if the index is valid.</li>
<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>
<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>
<li><code>addAtTail(val)</code> : Append a node of value <code>val</code>&nbsp;to the last element of the linked list.</li>
<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>
<li><code>deleteAtIndex(index)</code> : Delete&nbsp;the <code>index</code>-th&nbsp;node in the linked list, if the index is valid.</li>
</ul>

<p>&nbsp;</p>

<p><strong>Example:</strong></p>

<pre>
MyLinkedList linkedList = new MyLinkedList();
<b>Input: </b>
[&quot;MyLinkedList&quot;,&quot;addAtHead&quot;,&quot;addAtTail&quot;,&quot;addAtIndex&quot;,&quot;get&quot;,&quot;deleteAtIndex&quot;,&quot;get&quot;]
[[],[1],[3],[1,2],[1],[1],[1]]
<b>Output: </b>
[null,null,null,null,2,null,3]

<b>Explanation:</b>
MyLinkedList linkedList = new MyLinkedList(); // Initialize empty LinkedList
linkedList.addAtHead(1);
linkedList.addAtTail(3);
linkedList.addAtIndex(1, 2); // linked list becomes 1-&gt;2-&gt;3
Expand All @@ -35,12 +44,13 @@ linkedList.deleteAtIndex(1); // now the linked list is 1-&gt;3
linkedList.get(1);&nbsp;&nbsp;&nbsp; // returns 3
</pre>

<p><strong>Note:</strong></p>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li>All values will be in the range of <code>[1, 1000]</code>.</li>
<li>The number of operations will be in the range of&nbsp;<code>[1, 1000]</code>.</li>
<li><code>0 &lt;= index,val &lt;= 1000</code></li>
<li>Please do not use the built-in LinkedList library.</li>
<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>
</ul>

### Related Topics
Expand Down
Loading