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 d16f512 commit f946e8eCopy full SHA for f946e8e
1 file changed
two-sum/j2h30728.js
@@ -0,0 +1,18 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @param {number} target
4
+ * @return {number[]}
5
+ */
6
+var twoSum = function (nums, target) {
7
+ const map = new Map();
8
+
9
+ for (let i = 0; i < nums.length; i++) {
10
+ const num = target - nums[i];
11
+ if (map.has(num)) {
12
+ return [map.get(num), i];
13
+ }
14
+ map.set(nums[i], i);
15
16
17
+ return [];
18
+};
0 commit comments