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 cd4e26b commit 6d02612Copy full SHA for 6d02612
two-sum/DAEUN9.java
@@ -0,0 +1,15 @@
1
+import java.util.*;
2
+
3
+class Solution {
4
+ public int[] twoSum(int[] nums, int target) {
5
+ Map<Integer, Integer> existedMap = new HashMap<>();
6
+ for (int i = 0; i < nums.length; i++) {
7
+ int remain = target - nums[i];
8
+ if (existedMap.containsKey(remain)) {
9
+ return new int[]{existedMap.get(remain), i};
10
+ }
11
+ existedMap.put(nums[i], i);
12
13
+ return new int[]{0, 0};
14
15
+}
0 commit comments