Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 1 addition & 1 deletion
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-
finalint 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

Lines changed: 3 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /