You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-36
Original file line number
Diff line number
Diff line change
@@ -13,59 +13,59 @@ I have planned a learning route for you. You just need to do the problems in the
13
13
You can skip the more difficult problems and do them later.
14
14
15
15
# Brute Force
16
-
-[503. Next Greater Element II](solutions/0503-next-greater-element-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
16
+
-[503. Next Greater Element II](solutions/1-1000/503-next-greater-element-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
17
17
18
18
# Dynamic Programming
19
19
## Basics
20
-
-[509. Fibonacci Number](solutions/0509-fibonacci-number.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
20
+
-[509. Fibonacci Number](solutions/1-1000/509-fibonacci-number.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
21
21
22
22
## House Robber
23
-
-[198. House Robber](solutions/0198-house-robber.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
24
-
-[213. House Robber II](solutions/0213-house-robber-ii.md) was solved in _Python, JavaScript, Go_.
25
-
-[337. House Robber III](solutions/0337-house-robber-iii.md) was solved in _Python, JavaScript, Go_ and **2** solutions.
23
+
-[198. House Robber](solutions/1-1000/198-house-robber.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
24
+
-[213. House Robber II](solutions/1-1000/213-house-robber-ii.md) was solved in _Python, JavaScript, Go_.
25
+
-[337. House Robber III](solutions/1-1000/337-house-robber-iii.md) was solved in _Python, JavaScript, Go_ and **2** solutions.
26
26
27
27
## Knapsack Problems
28
28
### 0/1 Knapsack
29
-
-[416. Partition Equal Subset Sum](solutions/0416-partition-equal-subset-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
30
-
-[1049. Last Stone Weight II](solutions/1049-last-stone-weight-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
31
-
-[494. Target Sum](solutions/0494-target-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
32
-
-[474. Ones and Zeroes](solutions/0474-ones-and-zeroes.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
29
+
-[416. Partition Equal Subset Sum](solutions/1-1000/416-partition-equal-subset-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
30
+
-[1049. Last Stone Weight II](solutions/1001-2000/1049-last-stone-weight-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
31
+
-[494. Target Sum](solutions/1-1000/494-target-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
32
+
-[474. Ones and Zeroes](solutions/1-1000/474-ones-and-zeroes.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
33
33
34
34
### Unbounded Knapsack
35
-
-[518. Coin Change II](solutions/0518-coin-change-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
36
-
-[377. Combination Sum IV](solutions/0377-combination-sum-iv.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
37
-
-[322. Coin Change](solutions/0322-coin-change.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
38
-
-[279. Perfect Squares](solutions/0279-perfect-squares.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
39
-
-[139. Word Break](solutions/0139-word-break.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
35
+
-[518. Coin Change II](solutions/1-1000/518-coin-change-ii.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
36
+
-[377. Combination Sum IV](solutions/1-1000/377-combination-sum-iv.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
37
+
-[322. Coin Change](solutions/1-1000/322-coin-change.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
38
+
-[279. Perfect Squares](solutions/1-1000/279-perfect-squares.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
39
+
-[139. Word Break](solutions/1-1000/139-word-break.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
40
40
41
41
## Stock Maximum Profit Problems
42
-
-[121. Best Time to Buy and Sell Stock](solutions/0121-best-time-to-buy-and-sell-stock.md) was solved in _Python, JavaScript, Go_.
43
-
-[122. Best Time to Buy and Sell Stock II](solutions/0122-best-time-to-buy-and-sell-stock-ii.md) was solved in _Python, JavaScript, Go_.
44
-
-[714. Best Time to Buy and Sell Stock with Transaction Fee](solutions/0714-best-time-to-buy-and-sell-stock-with-transaction-fee.md) was solved in _Python, JavaScript, Go_.
45
-
-[123. Best Time to Buy and Sell Stock III](solutions/0123-best-time-to-buy-and-sell-stock-iii.md) was solved in _Python, JavaScript, Go_.
46
-
-[188. Best Time to Buy and Sell Stock IV](solutions/0188-best-time-to-buy-and-sell-stock-iv.md) was solved in _Python, JavaScript, Go_.
47
-
-[309. Best Time to Buy and Sell Stock with Cooldown](solutions/0309-best-time-to-buy-and-sell-stock-with-cooldown.md) was solved in _Python, JavaScript, Go_.
42
+
-[121. Best Time to Buy and Sell Stock](solutions/1-1000/121-best-time-to-buy-and-sell-stock.md) was solved in _Python, JavaScript, Go_.
43
+
-[122. Best Time to Buy and Sell Stock II](solutions/1-1000/122-best-time-to-buy-and-sell-stock-ii.md) was solved in _Python, JavaScript, Go_.
44
+
-[714. Best Time to Buy and Sell Stock with Transaction Fee](solutions/1-1000/714-best-time-to-buy-and-sell-stock-with-transaction-fee.md) was solved in _Python, JavaScript, Go_.
45
+
-[123. Best Time to Buy and Sell Stock III](solutions/1-1000/123-best-time-to-buy-and-sell-stock-iii.md) was solved in _Python, JavaScript, Go_.
46
+
-[188. Best Time to Buy and Sell Stock IV](solutions/1-1000/188-best-time-to-buy-and-sell-stock-iv.md) was solved in _Python, JavaScript, Go_.
47
+
-[309. Best Time to Buy and Sell Stock with Cooldown](solutions/1-1000/309-best-time-to-buy-and-sell-stock-with-cooldown.md) was solved in _Python, JavaScript, Go_.
48
48
49
49
## Subsequence Problems
50
-
-[674. Longest Continuous Increasing Subsequence](solutions/0674-longest-continuous-increasing-subsequence.md) was solved in _Python, Java, JavaScript, C#_.
51
-
-[300. Longest Increasing Subsequence](solutions/0300-longest-increasing-subsequence.md) was solved in _Python, Java, JavaScript, C#_.
52
-
-[718. Maximum Length of Repeated Subarray](solutions/0718-maximum-length-of-repeated-subarray.md) was solved in _Python, Java, JavaScript, C#_.
53
-
-[1143. Longest Common Subsequence](solutions/1143-longest-common-subsequence.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
54
-
-[1035. Uncrossed Lines](solutions/1035-uncrossed-lines.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
55
-
-[53. Maximum Subarray](solutions/0053-maximum-subarray.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
56
-
-[392. Is Subsequence](solutions/0392-is-subsequence.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
57
-
-[583. Delete Operation for Two Strings](solutions/0583-delete-operation-for-two-strings.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
58
-
-[72. Edit Distance](solutions/0072-edit-distance.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
50
+
-[674. Longest Continuous Increasing Subsequence](solutions/1-1000/674-longest-continuous-increasing-subsequence.md) was solved in _Python, Java, JavaScript, C#_.
51
+
-[300. Longest Increasing Subsequence](solutions/1-1000/300-longest-increasing-subsequence.md) was solved in _Python, Java, JavaScript, C#_.
52
+
-[718. Maximum Length of Repeated Subarray](solutions/1-1000/718-maximum-length-of-repeated-subarray.md) was solved in _Python, Java, JavaScript, C#_.
53
+
-[1143. Longest Common Subsequence](solutions/1001-2000/1143-longest-common-subsequence.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
54
+
-[1035. Uncrossed Lines](solutions/1001-2000/1035-uncrossed-lines.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
55
+
-[53. Maximum Subarray](solutions/1-1000/53-maximum-subarray.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
56
+
-[392. Is Subsequence](solutions/1-1000/392-is-subsequence.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
57
+
-[583. Delete Operation for Two Strings](solutions/1-1000/583-delete-operation-for-two-strings.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
58
+
-[72. Edit Distance](solutions/1-1000/72-edit-distance.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
59
59
60
60
# Monotonic Stack
61
-
-[739. Daily Temperatures](solutions/0739-daily-temperatures.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
62
-
-[496. Next Greater Element I](solutions/0496-next-greater-element-i.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
63
-
-[42. Trapping Rain Water](solutions/0042-trapping-rain-water.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
64
-
-[84. Largest Rectangle in Histogram](solutions/0084-largest-rectangle-in-histogram.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
61
+
-[739. Daily Temperatures](solutions/1-1000/739-daily-temperatures.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
62
+
-[496. Next Greater Element I](solutions/1-1000/496-next-greater-element-i.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
63
+
-[42. Trapping Rain Water](solutions/1-1000/42-trapping-rain-water.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
64
+
-[84. Largest Rectangle in Histogram](solutions/1-1000/84-largest-rectangle-in-histogram.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
65
65
66
66
# Graph Theory
67
-
-[797. All Paths From Source to Target](solutions/0797-all-paths-from-source-to-target.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
68
-
-[200. Number of Islands](solutions/0200-number-of-islands.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **3** solutions.
69
-
-[695. Max Area of Island](solutions/0695-max-area-of-island.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
67
+
-[797. All Paths From Source to Target](solutions/1-1000/797-all-paths-from-source-to-target.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2** solutions.
68
+
-[200. Number of Islands](solutions/1-1000/200-number-of-islands.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **3** solutions.
69
+
-[695. Max Area of Island](solutions/1-1000/695-max-area-of-island.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
Copy file name to clipboardExpand all lines: solutions/1-1000/200-number-of-islands-2.md
+11-13
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,11 @@ Output: 3
37
37
# Thoughts
38
38
The island problem can be abstracted into a **graph theory** problem. This is an **undirected graph**:
39
39
40
-

40
+

41
41
42
42
And this graph may have multiple **connected components** (islands):
43
43
44
-

44
+

45
45
46
46
Finding the number of islands is to find the number of `connected components`.
47
47
@@ -57,29 +57,27 @@ Walk from one node to the adjacent node until all nodes on the island are visite
57
57
1. Repeat the above two steps until all the lands have been `visited`.
58
58
59
59
### Solution 1: 'Depth-First Search' by Recursion
60
-
Please click [Depth-First Search by Recursion Solution](0200-number-of-islands.md) for `200. Number of Islands` to view.
60
+
Please click [Depth-First Search by Recursion Solution](200-number-of-islands.md) for `200. Number of Islands` to view.
61
61
62
62
## Solution 2: 'Depth-First Search' by Iteration
63
-

63
+

64
64
65
65
In solution 1, we have known how to traverse a graph by recursion. Computer language support for recursive calls is implemented through stacks.
66
66
For every recursive solution, there is an iterative solution, which means the same problem can be solved using loops.
67
67
The benefit of using iteration is better program performance. After all, recursive calls are expensive.
68
68
69
69
Maintaining a stack by yourself can accomplish the same function as recursive calls.
70
70
71
-
From this sample code bellow, you can see that starting from a node, through recursive calls, it goes up until it can't go any further, turns right, and continues up. The priority order of directions is `up, right, down, and left`.
72
-
```python
73
-
adjacent_points = [
74
-
(i, j -1), # left
75
-
(i +1, j), # down
76
-
(i, j +1), # right
77
-
(i -1, j), # up
78
-
]
71
+
From this sample code bellow, you can see that starting from a node, through recursive calls, it goes up until it can't go any further, turns right, and continues up. The priority order of directions is `up, right, down, left`.
72
+
```java
73
+
pointStack.push({i, j -1}); // left
74
+
pointStack.push({i +1, j}); // down
75
+
pointStack.push({i, j +1}); // right
76
+
pointStack.push({i -1, j}); // up
79
77
```
80
78
81
79
## Solution 3: Breadth-First Search
82
-
Please click [Breadth-First Search Solution](0200-number-of-islands-3.md) for `200. Number of Islands` to view.
80
+
Please click [Breadth-First Search Solution](200-number-of-islands-3.md) for `200. Number of Islands` to view.
Copy file name to clipboardExpand all lines: solutions/1-1000/200-number-of-islands.md
+11-13
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,11 @@ Output: 3
37
37
# Thoughts
38
38
The island problem can be abstracted into a **graph theory** problem. This is an **undirected graph**:
39
39
40
-

40
+

41
41
42
42
And this graph may have multiple **connected components** (islands):
43
43
44
-

44
+

45
45
46
46
Finding the number of islands is to find the number of `connected components`.
47
47
@@ -57,23 +57,21 @@ Walk from one node to the adjacent node until all nodes on the island are visite
57
57
1. Repeat the above two steps until all the lands have been `visited`.
58
58
59
59
## Solution 1: 'Depth-First Search' by Recursion
60
-

60
+

61
61
62
-
From this sample code bellow, you can see that starting from a node, through recursive calls, it goes up until it can't go any further, turns right, and continues up. The priority order of directions is `up, right, down, and left`.
63
-
```python
64
-
adjacent_points = [
65
-
(i -1, j), # up
66
-
(i, j +1), # right
67
-
(i +1, j), # down
68
-
(i, j -1), # left
69
-
]
62
+
From this sample code bellow, you can see that starting from a node, through recursive calls, it goes up until it can't go any further, turns right, and continues up. The priority order of directions is `up, right, down, left`.
63
+
```java
64
+
depth_first_search(i -1, j); // up
65
+
depth_first_search(i, j +1); // right
66
+
depth_first_search(i +1, j); // down
67
+
depth_first_search(i, j -1); // left
70
68
```
71
69
72
70
## Solution 2: 'Depth-First Search' by Iteration
73
-
Please click [Depth-First Search by Iteration Solution](0200-number-of-islands-2.md) for `200. Number of Islands` to view.
71
+
Please click [Depth-First Search by Iteration Solution](200-number-of-islands-2.md) for `200. Number of Islands` to view.
74
72
75
73
## Solution 3: Breadth-First Search
76
-
Please click [Breadth-First Search Solution](0200-number-of-islands-3.md) for `200. Number of Islands` to view.
74
+
Please click [Breadth-First Search Solution](200-number-of-islands-3.md) for `200. Number of Islands` to view.
Copy file name to clipboardExpand all lines: solutions/1-1000/494-target-sum.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Constraints:
38
38
```
39
39
40
40
* This problem is quite difficult if you have not solved similar problems before. So before you start working on this question,
41
-
it is recommended that you first work on another relatively simple question [416. Partition Equal Subset Sum](./0416-partition-equal-subset-sum.md) that is similar to this one.
41
+
it is recommended that you first work on another relatively simple question [416. Partition Equal Subset Sum](416-partition-equal-subset-sum.md) that is similar to this one.
42
42
43
43
## Thoughts
44
44
* When we see a set of numbers being used once to obtain another number through some calculation (just like this question), we can consider this to be a `0/1 Knapsack Problem`.
0 commit comments