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