Skip to content

Commit a583038

Browse files
refactor 1
1 parent 0b6c608 commit a583038

File tree

1 file changed

+2
-5
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-5
lines changed

src/main/java/com/fishercoder/solutions/_1.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ public class _1 {
1818
public static class Solution1 {
1919
public int[] twoSum(int[] nums, int target) {
2020
Map<Integer, Integer> map = new HashMap();
21-
int[] result = new int[2];
2221
for (int i = 0; i < nums.length; i++) {
2322
if (map.containsKey(target - nums[i])) {
24-
result[0] = map.get(target - nums[i]);
25-
result[1] = i;
26-
break;
23+
return new int[]{map.get(target - nums[i]), i};
2724
} else {
2825
map.put(nums[i], i);
2926
}
3027
}
31-
return result;
28+
return new int[]{-1, -1};
3229
}
3330
}
3431

0 commit comments

Comments
 (0)