8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
0 parents commit f9cdba0Copy full SHA for f9cdba0
1.two-sum.js
@@ -0,0 +1,26 @@
1
+/*
2
+ * @lc app=leetcode id=1 lang=javascript
3
+ *
4
+ * [1] Two Sum
5
+ */
6
+
7
+// @lc code=start
8
+/**
9
+ * @param {number[]} nums
10
+ * @param {number} target
11
+ * @return {number[]}
12
13
+var twoSum = function (nums, target) {
14
+ const map = new Map();
15
+ for (let index = 0; index < nums.length; index += 1) {
16
+ const num = nums[index];
17
+ const numToFind = target - num;
18
+ const index2 = map.get(numToFind);
19
+ if (index2 !== undefined) {
20
+ return [index2, index];
21
+ }
22
+ map.set(num, index);
23
24
+ return null;
25
+};
26
+// @lc code=end
0 commit comments