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

Add: new #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
awesee merged 1 commit into master from develop
Dec 23, 2019
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
9 changes: 7 additions & 2 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1298">1298</span> | [Maximum Candies You Can Get from Boxes](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes "你能从盒子里获得的最大糖果数") | [Go](problems/maximum-candies-you-can-get-from-boxes) | Hard |
| <span id="1297">1297</span> | [Maximum Number of Occurrences of a Substring](https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring "子串的最大出现次数") | [Go](problems/maximum-number-of-occurrences-of-a-substring) | Medium |
| <span id="1296">1296</span> | [Divide Array in Sets of K Consecutive Numbers](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers "划分数组为连续数字的集合") | [Go](problems/divide-array-in-sets-of-k-consecutive-numbers) | Medium |
| <span id="1295">1295</span> | [Find Numbers with Even Number of Digits](https://leetcode.com/problems/find-numbers-with-even-number-of-digits "统计位数为偶数的数字") | [Go](problems/find-numbers-with-even-number-of-digits) | Easy |
| <span id="1294">1294</span> | [Weather Type in Each Country](https://leetcode.com/problems/weather-type-in-each-country) 🔒 | [MySQL](problems/weather-type-in-each-country) | Easy |
| <span id="1293">1293</span> | [Shortest Path in a Grid with Obstacles Elimination](https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination "网格中的最短路径") | [Go](problems/shortest-path-in-a-grid-with-obstacles-elimination) | Hard |
| <span id="1292">1292</span> | [Maximum Side Length of a Square with Sum Less than or Equal to Threshold](https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold "元素和小于等于阈值的正方形的最大边长") | [Go](problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold) | Medium |
| <span id="1291">1291</span> | [Sequential Digits](https://leetcode.com/problems/sequential-digits "顺次数") | [Go](problems/sequential-digits) | Medium |
Expand All @@ -75,7 +80,7 @@ LeetCode Problems' Solutions
| <span id="1283">1283</span> | [Find the Smallest Divisor Given a Threshold](https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold "使结果不超过阈值的最小除数") | [Go](problems/find-the-smallest-divisor-given-a-threshold) | Medium |
| <span id="1282">1282</span> | [Group the People Given the Group Size They Belong To](https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to "用户分组") | [Go](problems/group-the-people-given-the-group-size-they-belong-to) | Medium |
| <span id="1281">1281</span> | [Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer "整数的各位积和之差") | [Go](problems/subtract-the-product-and-sum-of-digits-of-an-integer) | Easy |
| <span id="1280">1280</span> | [Students and Examinations](https://leetcode.com/problems/students-and-examinations) 🔒 | [MySQL](problems/students-and-examinations) | Easy |
| <span id="1280">1280</span> | [Students and Examinations](https://leetcode.com/problems/students-and-examinations "学生们参加各科测试的次数") 🔒 | [MySQL](problems/students-and-examinations) | Easy |
| <span id="1279">1279</span> | [Traffic Light Controlled Intersection](https://leetcode.com/problems/traffic-light-controlled-intersection) 🔒 | [Go](problems/traffic-light-controlled-intersection) | Easy |
| <span id="1278">1278</span> | [Palindrome Partitioning III](https://leetcode.com/problems/palindrome-partitioning-iii "分割回文串 III") | [Go](problems/palindrome-partitioning-iii) | Hard |
| <span id="1277">1277</span> | [Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones "统计全为 1 的正方形子矩阵") | [Go](problems/count-square-submatrices-with-all-ones) | Medium |
Expand Down Expand Up @@ -182,7 +187,7 @@ LeetCode Problems' Solutions
| <span id="1176">1176</span> | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") 🔒 | [Go](problems/diet-plan-performance) | Easy |
| <span id="1175">1175</span> | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements "质数排列") | [Go](problems/prime-arrangements) | Easy |
| <span id="1174">1174</span> | [Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii) 🔒 | [MySQL](problems/immediate-food-delivery-ii) | Medium |
| <span id="1173">1173</span> | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i) 🔒 | [MySQL](problems/immediate-food-delivery-i) | Easy |
| <span id="1173">1173</span> | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i "即时食物配送 I") 🔒 | [MySQL](problems/immediate-food-delivery-i) | Easy |
| <span id="1172">1172</span> | [Dinner Plate Stacks](https://leetcode.com/problems/dinner-plate-stacks "餐盘栈") | [Go](problems/dinner-plate-stacks) | Hard |
| <span id="1171">1171</span> | [Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list "从链表中删去总和值为零的连续节点") | [Go](problems/remove-zero-sum-consecutive-nodes-from-linked-list) | Medium |
| <span id="1170">1170</span> | [Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character "比较字符串最小字母出现频次") | [Go](problems/compare-strings-by-frequency-of-the-smallest-character) | Easy |
Expand Down
4 changes: 3 additions & 1 deletion internal/leetcode/topic_tag.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (tag *TagType) SaveContents() {
if question.TranslatedTitle == "" {
question.TranslatedTitle = question.Title
}
buf.WriteString(fmt.Sprintf(format, question.frontendID(), question.TranslatedTitle, question.TitleSlug, question.IsPaidOnly.Str(), question.TagsStr(), question.Difficulty))
if question.frontendID() > 0 {
buf.WriteString(fmt.Sprintf(format, question.frontendID(), question.TranslatedTitle, question.TitleSlug, question.IsPaidOnly.Str(), question.TagsStr(), question.Difficulty))
}
}
filename := filepath.Join("tag", tag.Slug, "README.md")
filePutContents(filename, buf.Bytes())
Expand Down
2 changes: 1 addition & 1 deletion problems/best-meeting-point/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Explanation: </strong>Given three people living at <code>(0,0)</code>, <code>(0,
&nbsp; of 2+2+2=6 is minimal. So return 6.</pre>

### Related Topics
[[Sort](../../tag/sort/README.md)]
[[Math](../../tag/math/README.md)]
[[Sort](../../tag/sort/README.md)]

### Similar Questions
1. [Shortest Distance from All Buildings](../shortest-distance-from-all-buildings) (Hard)
Expand Down
51 changes: 38 additions & 13 deletions problems/copy-list-with-random-pointer/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,53 @@

<p>Return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list.</p>

<p>&nbsp;</p>
<p>The Linked List is represented in the input/output as a list of <code>n</code> nodes. Each node is represented as a pair of <code>[val, random_index]</code> where:</p>

<ul>
<li><code>val</code>: an integer representing <code>Node.val</code></li>
<li><code>random_index</code>: the index of the node (range from <code>0</code> to <code>n-1</code>) where random pointer points to, or <code>null</code> if it does not point to any node.</li>
</ul>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/e1.png" style="width: 700px; height: 142px;" />
<pre>
<strong>Input:</strong> head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
<strong>Output:</strong> [[7,null],[13,0],[11,4],[10,2],[1,0]]
</pre>

<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/e2.png" style="width: 700px; height: 114px;" />
<pre>
<strong>Input:</strong> head = [[1,1],[2,1]]
<strong>Output:</strong> [[1,1],[2,1]]
</pre>

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

<p><strong><img alt="" src="https://discuss.leetcode.com/uploads/files/1470150906153-2yxeznm.png" style="width: 375px; height: 129px;" /></strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/e3.png" style="width: 700px; height: 122px;" /></strong></p>

<pre>
<strong>Input:
</strong><span id="example-input-1-1">{&quot;$id&quot;:&quot;1&quot;,&quot;next&quot;:{&quot;$id&quot;:&quot;2&quot;,&quot;next&quot;:null,&quot;random&quot;:{&quot;$ref&quot;:&quot;2&quot;},&quot;val&quot;:2},&quot;random&quot;:{&quot;$ref&quot;:&quot;2&quot;},&quot;val&quot;:1}
</span>
<b>Explanation:
</b>Node 1&#39;s value is 1, both of its next and random pointer points to Node 2.
Node 2&#39;s value is 2, its next pointer points to null and its random pointer points to itself.
<strong>Input:</strong> head = [[3,null],[3,0],[3,null]]
<strong>Output:</strong> [[3,null],[3,0],[3,null]]
</pre>

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

<p><strong>Note:</strong></p>
<pre>
<strong>Input:</strong> head = []
<strong>Output:</strong> []
<strong>Explanation:</strong> Given linked list is empty (null pointer), so return null.
</pre>

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

<ol>
<li>You must return the <strong>copy of the given head</strong>&nbsp;as a reference to the cloned list.</li>
</ol>
<ul>
<li><code>-10000 &lt;= Node.val &lt;= 10000</code></li>
<li><code>Node.random</code> is null or pointing to a node in the linked list.</li>
<li>Number of Nodes will not exceed 1000.</li>
</ul>

### Related Topics
[[Hash Table](../../tag/hash-table/README.md)]
Expand Down
76 changes: 76 additions & 0 deletions problems/divide-array-in-sets-of-k-consecutive-numbers/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--|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](../find-numbers-with-even-number-of-digits "Find Numbers with Even Number of Digits")

[Next >](../maximum-number-of-occurrences-of-a-substring "Maximum Number of Occurrences of a Substring")

## [1296. Divide Array in Sets of K Consecutive Numbers (Medium)](https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers "划分数组为连续数字的集合")

<p>Given an array of integers&nbsp;<code>nums</code>&nbsp;and a positive integer&nbsp;<code>k</code>, find whether it&#39;s possible to divide this array into&nbsp;sets of <code>k</code> consecutive numbers<br />
Return&nbsp;<code>True</code>&nbsp;if its possible<strong>&nbsp;</strong>otherwise&nbsp;return&nbsp;<code>False</code>.</p>

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

<pre>
<strong>Input:</strong> nums = [1,2,3,3,4,4,5,6], k = 4
<strong>Output:</strong> true
<strong>Explanation:</strong> Array can be divided into [1,2,3,4] and [3,4,5,6].
</pre>

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

<pre>
<strong>Input:</strong> nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3
<strong>Output:</strong> true
<strong>Explanation:</strong> Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].
</pre>

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

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

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4], k = 3
<strong>Output:</strong> false
<strong>Explanation:</strong> Each array should be divided in subarrays of size 3.
</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>
<li><code>1 &lt;= k &lt;= nums.length</code></li>
</ul>

### Related Topics
[[Greedy](../../tag/greedy/README.md)]
[[Array](../../tag/array/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
If the smallest number in the possible-to-split array is V, then numbers V+1, V+2, ... V+k-1 must contain there as well.
</details>

<details>
<summary>Hint 2</summary>
You can iteratively find k sets and remove them from array until it becomes empty.
</details>

<details>
<summary>Hint 3</summary>
Failure to do so would mean that array is unsplittable.
</details>
59 changes: 59 additions & 0 deletions problems/find-numbers-with-even-number-of-digits/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--|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](../weather-type-in-each-country "Weather Type in Each Country")

[Next >](../divide-array-in-sets-of-k-consecutive-numbers "Divide Array in Sets of K Consecutive Numbers")

## [1295. Find Numbers with Even Number of Digits (Easy)](https://leetcode.com/problems/find-numbers-with-even-number-of-digits "统计位数为偶数的数字")

Given an array <code>nums</code> of integers, return how many of them contain an <strong>even number</strong> of digits.
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [12,345,2,6,7896]
<strong>Output:</strong> 2
<strong>Explanation:
</strong>12 contains 2 digits (even number of digits).&nbsp;
345 contains 3 digits (odd number of digits).&nbsp;
2 contains 1 digit (odd number of digits).&nbsp;
6 contains 1 digit (odd number of digits).&nbsp;
7896 contains 4 digits (even number of digits).&nbsp;
Therefore only 12 and 7896 contain an even number of digits.
</pre>

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

<pre>
<strong>Input:</strong> nums = [555,901,482,1771]
<strong>Output:</strong> 1
<strong>Explanation: </strong>
Only 1771 contains an even number of digits.
</pre>

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

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

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

### Hints
<details>
<summary>Hint 1</summary>
How to compute the number of digits of a number ?
</details>

<details>
<summary>Hint 2</summary>
Divide the number by 10 again and again to get the number of digits.
</details>
2 changes: 1 addition & 1 deletion problems/flip-game-ii/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Derive your algorithm&#39;s runtime complexity.</p>

### Related Topics
[[Backtracking](../../tag/backtracking/README.md)]
[[Minimax](../../tag/minimax/README.md)]
[[Backtracking](../../tag/backtracking/README.md)]

### Similar Questions
1. [Nim Game](../nim-game) (Easy)
Expand Down
2 changes: 1 addition & 1 deletion problems/immediate-food-delivery-i/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Next >](../immediate-food-delivery-ii "Immediate Food Delivery II")

## [1173. Immediate Food Delivery I (Easy)](https://leetcode.com/problems/immediate-food-delivery-i "")
## [1173. Immediate Food Delivery I (Easy)](https://leetcode.com/problems/immediate-food-delivery-i "即时食物配送 I")

<p>Table: <code>Delivery</code></p>

Expand Down
93 changes: 93 additions & 0 deletions problems/maximum-candies-you-can-get-from-boxes/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--|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](../maximum-number-of-occurrences-of-a-substring "Maximum Number of Occurrences of a Substring")

Next >

## [1298. Maximum Candies You Can Get from Boxes (Hard)](https://leetcode.com/problems/maximum-candies-you-can-get-from-boxes "你能从盒子里获得的最大糖果数")

<p>Given <code>n</code> boxes, each box is given in the format <code>[status, candies, keys, containedBoxes]</code> where:</p>

<ul>
<li><code>status[i]</code>: an integer which is <strong>1</strong> if&nbsp;<code>box[i]</code> is open and <strong>0</strong> if&nbsp;<code>box[i]</code> is closed.</li>
<li><code>candies[i]</code>:&nbsp;an integer representing the number of candies in <code>box[i]</code>.</li>
<li><code>keys[i]</code>: an array contains the indices of the boxes you can open with the key in <code>box[i]</code>.</li>
<li><code>containedBoxes[i]</code>: an array contains the indices of the boxes found in <code>box[i]</code>.</li>
</ul>

<p>You will start with some boxes given in <code>initialBoxes</code> array. You can take all the candies in any open&nbsp;box and you can use the keys in it to open new boxes and you also can use the boxes you find in it.</p>

<p>Return <em>the maximum number of candies</em> you can get following the rules above.</p>

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

<pre>
<strong>Input:</strong> status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]
<strong>Output:</strong> 16
<strong>Explanation:</strong> You will be initially given box 0. You will find 7 candies in it and boxes 1 and 2. Box 1 is closed and you don&#39;t have a key for it so you will open box 2. You will find 4 candies and a key to box 1 in box 2.
In box 1, you will find 5 candies and box 3 but you will not find a key to box 3 so box 3 will remain closed.
Total number of candies collected = 7 + 4 + 5 = 16 candy.
</pre>

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

<pre>
<strong>Input:</strong> status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3,4,5],[],[],[],[],[]], initialBoxes = [0]
<strong>Output:</strong> 6
<strong>Explanation:</strong> You have initially box 0. Opening it you can find boxes 1,2,3,4 and 5 and their keys. The total number of candies will be 6.
</pre>

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

<pre>
<strong>Input:</strong> status = [1,1,1], candies = [100,1,100], keys = [[],[0,2],[]], containedBoxes = [[],[],[]], initialBoxes = [1]
<strong>Output:</strong> 1
</pre>

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

<pre>
<strong>Input:</strong> status = [1], candies = [100], keys = [[]], containedBoxes = [[]], initialBoxes = []
<strong>Output:</strong> 0
</pre>

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

<pre>
<strong>Input:</strong> status = [1,1,1], candies = [2,3,2], keys = [[],[],[]], containedBoxes = [[],[],[]], initialBoxes = [2,1,0]
<strong>Output:</strong> 7
</pre>

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

<ul>
<li><code>1 &lt;= status.length &lt;= 1000</code></li>
<li><code>status.length == candies.length == keys.length == containedBoxes.length == n</code></li>
<li><code>status[i]</code> is <code>0</code> or <code>1</code>.</li>
<li><code>1 &lt;= candies[i] &lt;= 1000</code></li>
<li><code><font face="monospace">0 &lt;= keys[i].length &lt;= status.length</font></code></li>
<li><code>0 &lt;= keys[i][j] &lt; status.length</code></li>
<li>All values in <code>keys[i]</code> are unique.</li>
<li><code><font face="monospace">0 &lt;= </font>containedBoxes<font face="monospace">[i].length &lt;= status.length</font></code></li>
<li><code>0 &lt;= containedBoxes[i][j] &lt; status.length</code></li>
<li>All values in <code>containedBoxes[i]</code> are unique.</li>
<li>Each box is contained in one box at most.</li>
<li><code>0 &lt;= initialBoxes.length&nbsp;&lt;= status.length</code></li>
<li><code><font face="monospace">0 &lt;= initialBoxes[i] &lt; status.length</font></code></li>
</ul>

### Related Topics
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Use Breadth First Search (BFS) to traverse all possible boxes you can open. Only push to the queue the boxes the you have with their keys.
</details>
Loading

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