Skip to content

Commit 1a47041

Browse files
committed
update: 001
1 parent b5c0f14 commit 1a47041

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

note/001/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Solution {
4444
```java
4545
class Solution {
4646
public int[] twoSum(int[] nums, int target) {
47-
final int len = nums.length;
47+
int len = nums.length;
4848
HashMap<Integer, Integer> map = new HashMap<>();
4949
for (int i = 0; i < len; ++i) {
5050
final Integer value = map.get(nums[i]);

src/com/blankj/easy/_001/Solution.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public int[] twoSum(int[] nums, int target) {
2727
int len = nums.length;
2828
HashMap<Integer, Integer> map = new HashMap<>();
2929
for (int i = 0; i < len; ++i) {
30-
if (map.containsKey(nums[i])) {
31-
return new int[]{map.get(nums[i]), i};
30+
final Integer value = map.get(nums[i]);
31+
if (value != null) {
32+
return new int[] { value, i };
3233
}
3334
map.put(target - nums[i], i);
3435
}

0 commit comments

Comments
 (0)