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 a5505e1

Browse filesBrowse files
committed
update: 001
1 parent 2d53c02 commit a5505e1
Copy full SHA for a5505e1

File tree

1 file changed

+4
-3
lines changed
Filter options

1 file changed

+4
-3
lines changed

‎note/001/README.md

Copy file name to clipboardExpand all lines: note/001/README.md
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ class Solution {
4444
```java
4545
class Solution {
4646
public int[] twoSum(int[] nums, int target) {
47-
int len = nums.length;
47+
final int len = nums.length;
4848
HashMap<Integer, Integer> map = new HashMap<>();
4949
for (int i = 0; i < len; ++i) {
50-
if (map.containsKey(nums[i])) {
51-
return new int[]{map.get(nums[i]), i};
50+
final Integer value = map.get(nums[i]);
51+
if (value != null) {
52+
return new int[] { value, i };
5253
}
5354
map.put(target - nums[i], i);
5455
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.