Skip to content

Commit 7734d45

Browse files
committed
two-sums
1 parent c5c2c17 commit 7734d45

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

two-sum/runnz121.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
public class runnz121 {
5+
6+
public class Solution {
7+
8+
public int[] twoSum(int[] nums, int target) {
9+
10+
Map<Integer, Integer> map = new HashMap<>();
11+
12+
for (int i = 0; i < nums.length; i++) {
13+
14+
int remain = target - nums[i];
15+
16+
if (map.containsKey(remain)) {
17+
return new int[]{map.get(remain), i};
18+
}
19+
20+
map.put(nums[i], i);
21+
}
22+
23+
return new int[]{0, 0};
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)