Skip to content

Commit e62b68c

Browse files
committed
add 001
1 parent 11fc229 commit e62b68c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
| 217 | [Contains Duplicate][217] |
2222
| 136 | [Single Number][136] |
2323
| 350 | [Intersection of Two Arrays II][350] |
24-
| 66 | [Plus One][066] |
24+
| 66 | [Plus One][066] |
2525
| 283 | [Move Zeroes][283] |
26-
26+
| 1 | [Two Sum][001] |
2727

2828
**其他**
2929

@@ -46,3 +46,4 @@
4646
[350]: https://github.com/andavid/leetcode-java/blob/master/note/350/README.md
4747
[066]: https://github.com/andavid/leetcode-java/blob/master/note/066/README.md
4848
[283]: https://github.com/andavid/leetcode-java/blob/master/note/283/README.md
49+
[001]: https://github.com/andavid/leetcode-java/blob/master/note/001/README.md

note/001/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [xxx][title]
2+
3+
## Description
4+
5+
6+
## 思路
7+
8+
9+
## [完整代码][src]
10+
11+
```java
12+
13+
```
14+
15+
[title]: https://leetcode.com/problems/xxx
16+
[src]: https://github.com/andavid/leetcode-java/blob/master/src/com/andavid/leetcode/_xxx/Solution.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] twoSum(int[] nums, int target) {
5+
if (nums == null || nums.length < 2) {
6+
return null;
7+
}
8+
9+
Map<Integer, Integer> map = new HashMap<>();
10+
for (int i = 0; i < nums.length; i++) {
11+
if (map.containsKey(target - nums[i])) {
12+
int[] result = new int[2];
13+
result[0] = map.get(target - nums[i]);
14+
result[1] = i;
15+
return result;
16+
}
17+
map.put(nums[i], i);
18+
}
19+
20+
return null;
21+
}
22+
23+
public static void main(String[] args) {
24+
Solution solution = new Solution();
25+
int[] nums = solution.twoSum(new int[]{2, 7, 11, 15}, 9);
26+
for (int i = 0; i < nums.length; i++) {
27+
System.out.print(i == 0 ? nums[i] : "," + nums[i]);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)