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 615e4bd commit 18cd90aCopy full SHA for 18cd90a
Easy/1. Two Sum.js
@@ -35,16 +35,11 @@ Output: [0,1]
35
* @return {number[]}
36
*/
37
var twoSum = function (nums, target) {
38
- var s = 0; //initilize a pointer to 0
39
- for (let i = 1; i < nums.length; i++) { //itterate 1 to length
+ return nums.map((s,i)=>{
40
if ((nums[s] + nums[i]) == target) { //check the pointer is equal to the target number or not
41
return [s, i]; //return if both sum are equal to the target
42
}
43
- if (i == nums.length - 1) { //if i equal to the length-1 then reinitilize it's to s+1
44
- i = s + 1;
45
- s++;
46
- }
47
+ })
48
49
var nums = [3, 2, 4], target = 6;
50
-console.log(twoSum(nums, target));
+console.log(twoSum(nums, target));
0 commit comments