Skip to content

Commit dd35298

Browse files
authored
Merge pull request bibhuti9#3 from RandeepSingh72/patch-1
Update 1. Two Sum.js
2 parents 615e4bd + 18cd90a commit dd35298

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

Easy/1. Two Sum.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ Output: [0,1]
3535
* @return {number[]}
3636
*/
3737
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
38+
return nums.map((s,i)=>{
4039
if ((nums[s] + nums[i]) == target) { //check the pointer is equal to the target number or not
4140
return [s, i]; //return if both sum are equal to the target
4241
}
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-
}
42+
})
4843
}
4944
var nums = [3, 2, 4], target = 6;
50-
console.log(twoSum(nums, target));
45+
console.log(twoSum(nums, target));

0 commit comments

Comments
 (0)