Skip to content

Instantly share code, notes, and snippets.

@Linkding
Created May 13, 2017 12:52
Show Gist options
  • Save Linkding/2f1d9209a4a00537845d20edfc57cf20 to your computer and use it in GitHub Desktop.
Save Linkding/2f1d9209a4a00537845d20edfc57cf20 to your computer and use it in GitHub Desktop.
1_to_sum.js
/**
* @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