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 e2b6507 commit 0e1b8faCopy full SHA for 0e1b8fa
two-sum/yoonthecoder.js
@@ -0,0 +1,14 @@
1
+var twoSum = function (nums, target) {
2
+ const map = new Map();
3
+
4
+ for (let i = 0; i < nums.length; i++) {
5
+ const complement = target - nums[i];
6
+ if (map.has(complement)) {
7
+ return [map.get(complement), i];
8
+ }
9
+ map.set(nums[i], i);
10
11
+};
12
13
+// Time complexity: O(n)
14
+// Space complexity: O(n) - hash map storage
0 commit comments