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 f291ae8 commit e0a1922Copy full SHA for e0a1922
two-sum/YoungSeok-Choi.java
@@ -0,0 +1,20 @@
1
+// time complexity: O(n);
2
+
3
+// 특정 nums[i] 가 target이 되기위한 보수 (target - nums[i])를 candidate Map에서 찾으면 종료
4
+class Solution {
5
+ public int[] twoSum(int[] nums, int target) {
6
+ Map<Integer, Integer> candidate = new HashMap<>();
7
8
+ for(int i = 0; i < nums.length; i++) {
9
10
+ int diff = target - nums[i];
11
12
+ if(candidate.containsKey(diff)) {
13
+ return new int[] { candidate.get(diff), i };
14
+ }
15
16
+ candidate.put(nums[i], i);
17
18
+ return new int[0];
19
20
+}
0 commit comments