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 a0fc24d commit 6e7c9c1Copy full SHA for 6e7c9c1
two-sum/taekwon-dev.java
@@ -0,0 +1,18 @@
1
+/**
2
+ * 시간/공간 복잡도: O(n)
3
+ */
4
+class Solution {
5
+ public int[] twoSum(int[] nums, int target) {
6
+ Map<Integer, Integer> map = new HashMap<>();
7
+
8
+ for (int idx = 0; idx < nums.length; idx++) {
9
+ int complement = target - nums[idx];
10
+ if (map.containsKey(complement)) {
11
+ return new int[]{map.get(complement), idx};
12
+ }
13
+ map.put(nums[idx], idx);
14
15
16
+ return new int[]{-1, -1};
17
18
+}
0 commit comments