Skip to content

Commit 73a9f5a

Browse files
authored
Updated twoSum.java
With testing on leetCode, the function twoSum returned indices that were added by 1 integer. Ex. if the actual result was [1, 2], the method returned [2, 3]. Deleted the i+1 in the if & else statements. This works.
1 parent fefe215 commit 73a9f5a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

TwoSum.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public int[] twoSum(int[] numbers, int target) {
2727
for (int i = 0; i < numbers.length; ++i) {
2828
int b = target - numbers[i];
2929
if (map.get(b) != null) {
30-
return new int[]{map.get(b),i+1};
31-
} else map.put(numbers[i],i+1);
30+
return new int[]{map.get(b),i};
31+
} else map.put(numbers[i],i);
3232
}
3333
return null;
3434
}
35-
}
35+
}

0 commit comments

Comments
 (0)