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 f39a12a commit 405949dCopy full SHA for 405949d
two-sum/JEONGBEOMKO.java
@@ -0,0 +1,22 @@
1
+package week01.twosum;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
6
+class Solution {
7
+ public int[] twoSum(int[] nums, int target) {
8
+ Map<Integer, Integer> numberMap = new HashMap<>();
9
+ for (int i=0; i<nums.length; i++) {
10
+ numberMap.put(nums[i], i);
11
+ }
12
13
+ for(int i=0; i<nums.length; i++) {
14
+ int operand = target - nums[i];
15
+ if (numberMap.containsKey(operand) && numberMap.get(operand) != i) { // 자기 자신은 제외
16
+ return new int[] { numberMap.get(target - nums[i]), i };
17
18
19
20
+ return new int[] {};
21
22
+}
0 commit comments