Skip to content

Commit 6d1f102

Browse files
refactor 1
1 parent 62d1504 commit 6d1f102

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy