We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5cdcdfb commit 18e00c9Copy full SHA for 18e00c9
1 file changed
L-I/0009 TwoSum/TwoSum.js
@@ -0,0 +1,25 @@
1
+const TwoSum = (nums, target) => {
2
+ numToIndex = {};
3
+
4
+ for (let i = 0; i < nums.length; i++) {
5
+ if (target - nums[i] in numToIndex)
6
+ return [numToIndex[target - nums[i]], i];
7
8
+ numToIndex[nums[i]] = i;
9
+ }
10
11
+ return [];
12
+};
13
14
+nums = [3, 2, 4];
15
+target = 6;
16
17
+nums1 = [2, 7, 11, 15];
18
+target1 = 9;
19
20
+nums2 = [3, 3];
21
+target2 = 6;
22
23
+console.log(TwoSum(nums, target));
24
+console.log(TwoSum(nums1, target1));
25
+console.log(TwoSum(nums2, target2));
0 commit comments