// 给定 nums = [2, 7, 11, 15], target = 9 // 因为 nums[0] + nums[1] = 2 + 7 = 9 // 所以返回 [0, 1]
console
.log(func([2, 7, 11, 15], 9));
function func(nums
, target
) {
for (let i
= 0; i
< nums
.length
; i
++) {
for (let j
= 0; j
< nums
.length
; j
++) {
if (nums
[i
] + nums
[j
] === target
&& i
!== j
) {
return [i
, j
];
}
}
}
}