Created
May 13, 2017 12:52
-
-
Save Linkding/2f1d9209a4a00537845d20edfc57cf20 to your computer and use it in GitHub Desktop.
1_to_sum.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @param {number} target | |
* @return {number[]} | |
*/ | |
var twoSum = function(nums, target) { | |
len = nums.length; | |
//console.log(len) | |
var res = []; | |
for (i=0; i<len; i++){ | |
for (f=i+1; f<len; f++){ | |
if (nums[i] + nums[f] == target){ | |
res.push(i,f); | |
} | |
/*else{ | |
console.log("not much") | |
}*/ | |
} | |
} | |
return res; | |
}; | |
console.log(twoSum([1,2,7],9)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment