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

Appearance settings

Commit 1a47041

Browse filesBrowse files
committed
update: 001
1 parent b5c0f14 commit 1a47041
Copy full SHA for 1a47041

File tree

2 files changed

+4
-3
lines changed
Filter options

2 files changed

+4
-3
lines changed

‎note/001/README.md

Copy file name to clipboardExpand all lines: note/001/README.md
+1-1Lines 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-
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

Copy file name to clipboardExpand all lines: src/com/blankj/easy/_001/Solution.java
+3-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.