数组中两数相加 等于一个值
1.暴力破解
var nums = [1, 3, 7, 6, 9, 11]; var target = 9; var o = [] for (let i = 0; i < nums.length; i++) { for (let j = 0; j < nums.length; j++) { let z = nums[i] let c = nums[j] if (z + c === target) { console.log(i,j) } } }
var nums = [1, 3, 7, 6, 9, 11]; var target = 9; var o = [] for (let i = 0; i < nums.length; i++) { for (let j = 0; j < nums.length; j++) { let z = nums[i] let c = nums[j] if (z + c === target) { console.log(i,j) } } }