要求:
- @input nums[]
- @input target
- @output res[index1,index2] 使得nums[index1]+nums[index2]=target
思路:
暴力遍历
代码:
var twoSum = function(nums, target) {
var res=[]
var length=nums.length
for(var i=0; i<length; i++){
res[0] = i
for(var j=i+1; j<length; j++){
res[1] = j
if(nums[i]+nums[j]===target){
return res
}
}
}
};