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
+12-11
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ You can skip the more difficult problems and do them later.
14
14
15
15
# Array
16
16
-[704. Binary Search](solutions/1-1000/704-binary-search.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
17
-
-[27. Remove Element](solutions/1-1000/27-remove-element.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2**solutions.
17
+
-[27. Remove Element](solutions/1-1000/27-remove-element.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2**ways.
18
18
-[977. Squares of a Sorted Array](solutions/1-1000/977-squares-of-a-sorted-array.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
19
19
-[209. Minimum Size Subarray Sum](solutions/1-1000/209-minimum-size-subarray-sum.md) was solved in _Python, Java, JavaScript, C#_.
20
20
-[303. Range Sum Query - Immutable](solutions/1-1000/303-range-sum-query-immutable.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
@@ -35,6 +35,7 @@ You can skip the more difficult problems and do them later.
35
35
-[1. Two Sum](solutions/1-1000/1-two-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
36
36
-[202. Happy Number](solutions/1-1000/202-happy-number.md) was solved in _Python, Java, JavaScript, C#_.
37
37
-[454. 4Sum II](solutions/1-1000/454-4sum-ii.md) was solved in _Python, Java, JavaScript, C#, Ruby_.
38
+
-[15. 3Sum](solutions/1-1000/15-3sum.md) was solved in _Python_ and 2 ways.
38
39
39
40
# Dynamic Programming
40
41
## Basics
@@ -43,12 +44,12 @@ You can skip the more difficult problems and do them later.
43
44
## House Robber
44
45
-[198. House Robber](solutions/1-1000/198-house-robber.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
45
46
-[213. House Robber II](solutions/1-1000/213-house-robber-ii.md) was solved in _Python, JavaScript, Go_.
46
-
-[337. House Robber III](solutions/1-1000/337-house-robber-iii.md) was solved in _Python, JavaScript, Go_ and **2**solutions.
47
+
-[337. House Robber III](solutions/1-1000/337-house-robber-iii.md) was solved in _Python, JavaScript, Go_ and **2**ways.
47
48
48
49
## Knapsack Problems
49
50
### 0/1 Knapsack
50
-
-[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.
51
-
-[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.
51
+
-[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**ways.
52
+
-[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**ways.
52
53
-[494. Target Sum](solutions/1-1000/494-target-sum.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
53
54
-[474. Ones and Zeroes](solutions/1-1000/474-ones-and-zeroes.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
54
55
@@ -81,20 +82,20 @@ You can skip the more difficult problems and do them later.
81
82
# Monotonic Stack
82
83
-[739. Daily Temperatures](solutions/1-1000/739-daily-temperatures.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
83
84
-[496. Next Greater Element I](solutions/1-1000/496-next-greater-element-i.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
84
-
-[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.
85
+
-[42. Trapping Rain Water](solutions/1-1000/42-trapping-rain-water.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **2**ways.
85
86
-[84. Largest Rectangle in Histogram](solutions/1-1000/84-largest-rectangle-in-histogram.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
86
87
87
88
# Graph Theory
88
-
-[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.
89
-
-[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.
90
-
-[463. Island Perimeter](solutions/1-1000/463-island-perimeter.md) was solved in _Python_ and **2**solutions.
89
+
-[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**ways.
90
+
-[200. Number of Islands](solutions/1-1000/200-number-of-islands.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and **3**ways.
91
+
-[463. Island Perimeter](solutions/1-1000/463-island-perimeter.md) was solved in _Python_ and **2**ways.
91
92
-[695. Max Area of Island](solutions/1-1000/695-max-area-of-island.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
92
93
-[827. Making A Large Island](solutions/1-1000/827-making-a-large-island.md) was solved in _Python_.
93
94
-[127. Word Ladder](solutions/1-1000/127-word-ladder.md) was solved in _Python_.
94
-
-[1971. Find if Path Exists in Graph](solutions/1001-2000/1971-find-if-path-exists-in-graph.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 solutions.
95
+
-[1971. Find if Path Exists in Graph](solutions/1001-2000/1971-find-if-path-exists-in-graph.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 ways.
95
96
-[684. Redundant Connection](solutions/1-1000/684-redundant-connection.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_.
96
97
-[685. Redundant Connection II](solutions/1-1000/685-redundant-connection-ii.md) was solved in _Python_.
97
-
-[1584. Min Cost to Connect All Points](solutions/1001-2000/1584-min-cost-to-connect-all-points.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 solutions.
98
-
-[207. Course Schedule](solutions/1-1000/207-course-schedule.md) was solved in _Python, Java, C++, C#_ and 2 solutions.
98
+
-[1584. Min Cost to Connect All Points](solutions/1001-2000/1584-min-cost-to-connect-all-points.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 ways.
99
+
-[207. Course Schedule](solutions/1-1000/207-course-schedule.md) was solved in _Python, Java, C++, C#_ and 2 ways.
Copy file name to clipboardExpand all lines: solutions/1-1000/1-two-sum.md
+51-15
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Difficulty: **Easy**
31
31
-`-10**9 <= target <= 10**9`
32
32
-**Only one valid answer exists.**
33
33
34
-
## Solution 1
34
+
## Solution 1: Two pointers (should master)
35
35
[中文题解](#中文题解)
36
36
37
37
1. The time complexity of the brute force solution is `O(n**2)`. To improve efficiency, you can sort the array, and then use **two pointers**, one pointing to the head of the array and the other pointing to the tail of the array, and decide `left += 1` or `right -= 1` according to the comparison of `sum` and `target`.
@@ -41,7 +41,7 @@ Difficulty: **Easy**
41
41
* Time: `O(N * log N)`.
42
42
* Space: `O(N)`.
43
43
44
-
## Solution 2
44
+
## Solution 2: Use Map (also should master)
45
45
1. In `Map`, `key` is `num`, and `value` is array `index`.
46
46
2. Traverse the array, if `target - num` is in `Map`, return it. Otherwise, add `num` to `Map`.
47
47
@@ -73,6 +73,12 @@ for (let i = 0; i < nums.length; i++) {
73
73
* Space: `O(n)`.
74
74
75
75
## Java
76
+
### Solution 1: Two pointers
77
+
```java
78
+
// Welcome to create a PR to complete the code, thanks!
0 commit comments