We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b406f6f commit e2a17ceCopy full SHA for e2a17ce
two-sum/dohee789.java
@@ -6,16 +6,14 @@ public int[] twoSum(int[] nums, int target) {
6
Map<Integer, Integer> map = new HashMap<>();
7
8
for(int i = 0; i < nums.length; i++) {
9
- map.put(nums[i], i);
10
- }
11
-
12
- for(int i = 0; i < nums.length; i++) {
13
- if(map.containsKey(target - nums[i]) && map.get(target - nums[i]) != i) {
+ if(map.containsKey(target - nums[i])) {
14
int j = map.get(target - nums[i]);
15
return new int[]{i, j};
16
}
+ map.put(nums[i], i);
17
18
19
return null;
20
21
+
0 commit comments