/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
var num = []
for(var i = 0; i < nums.length; i++ ){
for(var j = 0; j < nums.length; j++ ){
if(target == (nums[i] + nums[j]) && i != j){
if(!num.length){
num = [i, j]
}
}
}
}
return num
};
console.log(twoSum([2,7,11,15], 9))
No comments:
Post a Comment