Skip to content

Commit 521a6c1

Browse files
author
Shuo
committed
A: new
1 parent a7c50eb commit 521a6c1

File tree

84 files changed

+1153
-1676
lines changed

Some content is hidden

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

84 files changed

+1153
-1676
lines changed

README.md

+18-11
Large diffs are not rendered by default.

problems/asteroid-collision/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<p><strong>Constraints:</strong></p>
5555

5656
<ul>
57-
<li><code>2 &lt;= asteroids &lt;= 10<sup>4</sup></code></li>
57+
<li><code>2 &lt;= asteroids.length&nbsp;&lt;= 10<sup>4</sup></code></li>
5858
<li><code>-1000 &lt;= asteroids[i] &lt;= 1000</code></li>
5959
<li><code>asteroids[i] != 0</code></li>
6060
</ul>

problems/biggest-window-between-visits/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
[Next >](../maximum-units-on-a-truck "Maximum Units on a Truck")
1111

12-
## [1709. Biggest Window Between Visits (Medium)](https://leetcode.com/problems/biggest-window-between-visits "")
12+
## [1709. Biggest Window Between Visits (Medium)](https://leetcode.com/problems/biggest-window-between-visits "访问日期之间最大的空档期")
1313

1414

problems/binary-search-tree-to-greater-sum-tree/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
</ul>
6464

6565
### Related Topics
66+
[[Tree](../../tag/tree/README.md)]
67+
[[Depth-first Search](../../tag/depth-first-search/README.md)]
6668
[[Binary Search Tree](../../tag/binary-search-tree/README.md)]
69+
[[Recursion](../../tag/recursion/README.md)]
6770

6871
### Hints
6972
<details>

problems/break-a-palindrome/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
## [1328. Break a Palindrome (Medium)](https://leetcode.com/problems/break-a-palindrome "破坏回文串")
1313

14-
<p>Given a palindromic string <code>palindrome</code>, replace <strong>exactly one</strong> character by any lowercase English letter so that the string becomes the lexicographically smallest possible string that <strong>isn&#39;t</strong> a palindrome.</p>
14+
<p>Given a palindromic string <code>palindrome</code>, replace <strong>exactly one</strong> character with any lowercase English letter so that the string becomes the <strong>lexicographically smallest</strong> possible string that is <strong>not</strong> a palindrome.</p>
1515

16-
<p>After doing so, return the final string.&nbsp; If there is no way to do so, return the empty string.</p>
16+
<p>After doing so, return <em>the final string. If there is no way to do so, return an empty string</em>.</p>
1717

1818
<p>&nbsp;</p>
1919
<p><strong>Example 1:</strong></p>
@@ -35,7 +35,7 @@
3535

3636
<ul>
3737
<li><code>1 &lt;= palindrome.length &lt;= 1000</code></li>
38-
<li><code>palindrome</code>&nbsp;consists of only lowercase English letters.</li>
38+
<li><code>palindrome</code> consists of only lowercase English letters.</li>
3939
</ul>
4040

4141
### Related Topics

problems/bus-routes/README.md

+25-11
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,42 @@
1111

1212
## [815. Bus Routes (Hard)](https://leetcode.com/problems/bus-routes "公交路线")
1313

14-
<p>We have a list of bus routes. Each <code>routes[i]</code> is a bus route that the i-th bus&nbsp;repeats forever. For example if <code>routes[0] = [1, 5, 7]</code>, this means that the first&nbsp;bus (0-th indexed) travels in the sequence 1-&gt;5-&gt;7-&gt;1-&gt;5-&gt;7-&gt;1-&gt;... forever.</p>
14+
<p>You are given an array <code>routes</code> representing bus routes where <code>routes[i]</code> is a bus route that the <code>i<sup>th</sup></code> bus repeats forever.</p>
1515

16-
<p>We start at bus stop <code>S</code> (initially not on a bus), and we want to go to bus stop <code>T</code>. Travelling by buses only, what is the least number of buses we must take to reach our destination? Return -1 if it is not possible.</p>
16+
<ul>
17+
<li>For example, if <code>routes[0] = [1, 5, 7]</code>, this means that the <code>0<sup>th</sup></code> bus travels in the sequence <code>1 -&gt; 5 -&gt; 7 -&gt; 1 -&gt; 5 -&gt; 7 -&gt; 1 -&gt; ...</code> forever.</li>
18+
</ul>
19+
20+
<p>You will start at the bus stop <code>source</code> (You are not on any bus initially), and you want to go to the bus stop <code>target</code>. You can travel between bus stops by buses only.</p>
21+
22+
<p>Return <em>the least number of buses you must take to travel from </em><code>source</code><em> to </em><code>target</code>. Return <code>-1</code> if it is not possible.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
1726

1827
<pre>
19-
<strong>Example:</strong>
20-
<strong>Input:</strong>
21-
routes = [[1, 2, 7], [3, 6, 7]]
22-
S = 1
23-
T = 6
28+
<strong>Input:</strong> routes = [[1,2,7],[3,6,7]], source = 1, target = 6
2429
<strong>Output:</strong> 2
25-
<strong>Explanation:</strong>
26-
The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.
30+
<strong>Explanation:</strong> The best strategy is take the first bus to the bus stop 7, then take the second bus to the bus stop 6.
31+
</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12
37+
<strong>Output:</strong> -1
2738
</pre>
2839

2940
<p>&nbsp;</p>
3041
<p><strong>Constraints:</strong></p>
3142

3243
<ul>
3344
<li><code>1 &lt;= routes.length &lt;= 500</code>.</li>
34-
<li><code>1 &lt;= routes[i].length &lt;= 10^5</code>.</li>
35-
<li><code>0 &lt;= routes[i][j] &lt; 10 ^ 6</code>.</li>
45+
<li><code>1 &lt;= routes[i].length &lt;= 10<sup>5</sup></code></li>
46+
<li>All the values of <code>routes[i]</code> are <strong>unique</strong>.</li>
47+
<li><code>sum(routes[i].length) &lt;= 10<sup>5</sup></code></li>
48+
<li><code>0 &lt;= routes[i][j] &lt; 10<sup>6</sup></code></li>
49+
<li><code>0 &lt;= source, target &lt; 10<sup>6</sup></code></li>
3650
</ul>
3751

3852
### Related Topics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../restore-the-array-from-adjacent-pairs "Restore the Array From Adjacent Pairs")
9+
                
10+
[Next >](../palindrome-partitioning-iv "Palindrome Partitioning IV")
11+
12+
## [1744. Can You Eat Your Favorite Candy on Your Favorite Day? (Medium)](https://leetcode.com/problems/can-you-eat-your-favorite-candy-on-your-favorite-day "你能在你最喜欢的那天吃到你最喜欢的糖果吗?")
13+
14+
<p>You are given a <strong>(0-indexed)</strong> array of positive integers <code>candiesCount</code> where <code>candiesCount[i]</code> represents the number of candies of the&nbsp;<code>i<sup>th</sup></code>&nbsp;type you have. You are also given a 2D array <code>queries</code> where <code>queries[i] = [favoriteType<sub>i</sub>, favoriteDay<sub>i</sub>, dailyCap<sub>i</sub>]</code>.</p>
15+
16+
<p>You play a game with the following rules:</p>
17+
18+
<ul>
19+
<li>You start eating candies on day <code><strong>0</strong></code>.</li>
20+
<li>You <b>cannot</b> eat <strong>any</strong> candy of type <code>i</code> unless you have eaten <strong>all</strong> candies of type <code>i - 1</code>.</li>
21+
<li>You must eat <strong>at least</strong> <strong>one</strong> candy per day until you have eaten all the candies.</li>
22+
</ul>
23+
24+
<p>Construct a boolean array <code>answer</code> such that <code>answer.length == queries.length</code> and <code>answer[i]</code> is <code>true</code> if you can eat a candy of type <code>favoriteType<sub>i</sub></code> on day <code>favoriteDay<sub>i</sub></code> without eating <strong>more than</strong> <code>dailyCap<sub>i</sub></code> candies on <strong>any</strong> day, and <code>false</code> otherwise. Note that you can eat different types of candy on the same day, provided that you follow rule 2.</p>
25+
26+
<p>Return <em>the constructed array </em><code>answer</code>.</p>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Example 1:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]
33+
<strong>Output:</strong> [true,false,true]
34+
<strong>Explanation:</strong>
35+
1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.
36+
2- You can eat at most 4 candies each day.
37+
If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.
38+
On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.
39+
3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.
40+
</pre>
41+
42+
<p><strong>Example 2:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]
46+
<strong>Output:</strong> [false,true,true,false,false]
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= candiesCount.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>1 &lt;= candiesCount[i] &lt;= 10<sup>5</sup></code></li>
55+
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
56+
<li><code>queries[i].length == 3</code></li>
57+
<li><code>0 &lt;= favoriteType<sub>i</sub> &lt; candiesCount.length</code></li>
58+
<li><code>0 &lt;= favoriteDay<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
59+
<li><code>1 &lt;= dailyCap<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
60+
</ul>
61+
62+
### Related Topics
63+
[[Math](../../tag/math/README.md)]
64+
65+
### Hints
66+
<details>
67+
<summary>Hint 1</summary>
68+
The query is true if and only if your favorite day is in between the earliest and latest possible days to eat your favorite candy.
69+
</details>
70+
71+
<details>
72+
<summary>Hint 2</summary>
73+
To get the earliest day, you need to eat dailyCap candies every day. To get the latest day, you need to eat 1 candy every day.
74+
</details>
75+
76+
<details>
77+
<summary>Hint 3</summary>
78+
The latest possible day is the total number of candies with a smaller type plus the number of your favorite candy minus 1.
79+
</details>
80+
81+
<details>
82+
<summary>Hint 4</summary>
83+
The earliest possible day that you can eat your favorite candy is the total number of candies with a smaller type divided by dailyCap.
84+
</details>

problems/checking-existence-of-edge-length-limited-paths-ii/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../number-of-rectangles-that-can-form-the-largest-square "Number Of Rectangles That Can Form The Largest Square")
1111

12-
## [1724. Checking Existence of Edge Length Limited Paths II (Hard)](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii "")
12+
## [1724. Checking Existence of Edge Length Limited Paths II (Hard)](https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii "检查边长度限制的路径是否存在 II")
1313

1414

1515

problems/concatenated-words/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
## [472. Concatenated Words (Hard)](https://leetcode.com/problems/concatenated-words "连接词")
1313

14-
<p>Given a list of words (<strong>without duplicates</strong>), please write a program that returns all concatenated words in the given list of words.</p>
14+
<p>Given an array of strings <code>words</code> (<strong>without duplicates</strong>), return <em>all the <strong>concatenated words</strong> in the given list of</em> <code>words</code>.</p>
1515

16-
<p>A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.</p>
16+
<p>A <strong>concatenated word</strong> is defined as a string that is comprised entirely of at least two shorter words in the given array.</p>
1717

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

problems/convert-bst-to-greater-tree/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@
6464

6565
### Related Topics
6666
[[Tree](../../tag/tree/README.md)]
67+
[[Depth-first Search](../../tag/depth-first-search/README.md)]
68+
[[Binary Search Tree](../../tag/binary-search-tree/README.md)]
69+
[[Recursion](../../tag/recursion/README.md)]

problems/copy-list-with-random-pointer/README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111

1212
## [138. Copy List with Random Pointer (Medium)](https://leetcode.com/problems/copy-list-with-random-pointer "复制带随机指针的链表")
1313

14-
<p>A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.</p>
14+
<p>A linked list of length <code>n</code> is given such that each node contains an additional random pointer, which could point to any node in the list, or <code>null</code>.</p>
1515

16-
<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>
16+
<p>Construct a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> of the list. The deep copy should consist of exactly <code>n</code> <strong>brand new</strong> nodes, where each new node has its value set to the value of its corresponding original node. Both the <code>next</code> and <code>random</code> pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. <strong>None of the pointers in the new list should point to nodes in the original list</strong>.</p>
1717

18-
<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>
18+
<p>For example, if there are two nodes <code>X</code> and <code>Y</code> in the original list, where <code>X.random --&gt; Y</code>, then for the corresponding two nodes <code>x</code> and <code>y</code> in the copied list, <code>x.random --&gt; y</code>.</p>
19+
20+
<p>Return <em>the head of the copied linked list</em>.</p>
21+
22+
<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>
1923

2024
<ul>
2125
<li><code>val</code>: an integer representing <code>Node.val</code></li>
22-
<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>
26+
<li><code>random_index</code>: the index of the node (range from <code>0</code> to <code>n-1</code>) that the <code>random</code> pointer points to, or <code>null</code> if it does not point to any node.</li>
2327
</ul>
2428

29+
<p>Your code will <strong>only</strong> be given the <code>head</code> of the original linked list.</p>
30+
2531
<p>&nbsp;</p>
2632
<p><strong>Example 1:</strong></p>
2733
<img alt="" src="https://assets.leetcode.com/uploads/2019/12/18/e1.png" style="width: 700px; height: 142px;" />
@@ -51,16 +57,16 @@
5157
<pre>
5258
<strong>Input:</strong> head = []
5359
<strong>Output:</strong> []
54-
<strong>Explanation:</strong> Given linked list is empty (null pointer), so return null.
60+
<strong>Explanation:</strong> The given linked list is empty (null pointer), so return null.
5561
</pre>
5662

5763
<p>&nbsp;</p>
5864
<p><strong>Constraints:</strong></p>
5965

6066
<ul>
67+
<li><code>0 &lt;= n &lt;= 1000</code></li>
6168
<li><code>-10000 &lt;= Node.val &lt;= 10000</code></li>
62-
<li><code>Node.random</code> is null or pointing to a node in the linked list.</li>
63-
<li>The number of nodes will not exceed 1000.</li>
69+
<li><code>Node.random</code> is <code>null</code> or is pointing to some node in the linked list.</li>
6470
</ul>
6571

6672
### Related Topics

problems/count-apples-and-oranges/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
[Next >](../calculate-money-in-leetcode-bank "Calculate Money in Leetcode Bank")
1111

12-
## [1715. Count Apples and Oranges (Medium)](https://leetcode.com/problems/count-apples-and-oranges "")
12+
## [1715. Count Apples and Oranges (Medium)](https://leetcode.com/problems/count-apples-and-oranges "苹果和橘子的个数")
1313

1414

problems/course-schedule-iv/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../cherry-pickup-ii "Cherry Pickup II")
1111

12-
## [1462. Course Schedule IV (Medium)](https://leetcode.com/problems/course-schedule-iv "课程安排 IV")
12+
## [1462. Course Schedule IV (Medium)](https://leetcode.com/problems/course-schedule-iv "课程表 IV")
1313

1414
<p>There are a total of <code>n</code> courses you have to take, labeled from <code>0</code> to <code>n-1</code>.</p>
1515

problems/course-schedule/README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,42 @@
1111

1212
## [207. Course Schedule (Medium)](https://leetcode.com/problems/course-schedule "课程表")
1313

14-
<p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses-1</code>.</p>
14+
<p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i</sub></code> first if you want to take course <code>a<sub>i</sub></code>.</p>
1515

16-
<p>Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: <code>[0,1]</code></p>
16+
<ul>
17+
<li>For example, the pair <code>[0, 1]</code>, indicates that to take course <code>0</code> you have to first take course <code>1</code>.</li>
18+
</ul>
1719

18-
<p>Given the total number of courses and a list of prerequisite <b>pairs</b>, is it possible for you to finish all courses?</p>
20+
<p>Return <code>true</code> if you can finish all courses. Otherwise, return <code>false</code>.</p>
1921

2022
<p>&nbsp;</p>
2123
<p><strong>Example 1:</strong></p>
2224

2325
<pre>
2426
<strong>Input:</strong> numCourses = 2, prerequisites = [[1,0]]
2527
<strong>Output:</strong> true
26-
<strong>Explanation:</strong>&nbsp;There are a total of 2 courses to take.
27-
&nbsp; To take course 1 you should have finished course 0. So it is possible.
28+
<strong>Explanation:</strong> There are a total of 2 courses to take.
29+
To take course 1 you should have finished course 0. So it is possible.
2830
</pre>
2931

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

3234
<pre>
3335
<strong>Input:</strong> numCourses = 2, prerequisites = [[1,0],[0,1]]
3436
<strong>Output:</strong> false
35-
<strong>Explanation:</strong>&nbsp;There are a total of 2 courses to take.
36-
&nbsp; To take course 1 you should have finished course 0, and to take course 0 you should
37-
&nbsp; also have finished course 1. So it is impossible.
37+
<strong>Explanation:</strong> There are a total of 2 courses to take.
38+
To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
3839
</pre>
3940

4041
<p>&nbsp;</p>
4142
<p><strong>Constraints:</strong></p>
4243

4344
<ul>
44-
<li>The input prerequisites is a graph represented by <b>a list of edges</b>, not adjacency matrices. Read more about <a href="https://www.khanacademy.org/computing/computer-science/algorithms/graph-representation/a/representing-graphs" target="_blank">how a graph is represented</a>.</li>
45-
<li>You may assume that there are no duplicate edges in the input prerequisites.</li>
46-
<li><code>1 &lt;=&nbsp;numCourses &lt;= 10^5</code></li>
45+
<li><code>1 &lt;= numCourses &lt;= 10<sup>5</sup></code></li>
46+
<li><code>0 &lt;= prerequisites.length &lt;= 5000</code></li>
47+
<li><code>prerequisites[i].length == 2</code></li>
48+
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt; numCourses</code></li>
49+
<li>All the pairs prerequisites[i] are <strong>unique</strong>.</li>
4750
</ul>
4851

4952
### Related Topics

0 commit comments

Comments
 (0)