题目:
我的答案:
/** * @param {number[]} nums * @param {number} target * @return {number[]} */ var twoSum = function(nums, target) { var len = nums.length; for(let i = 0;i<len;i++){ for(let j = 0;j<len;j++){ if(i!=j){ var sum = nums[i]+nums[j]; if(sum === target){ return [i,j]; } } } } }; var nums = [1,2,3,4,5]; twoSum(nums,9);
时间: 2024-11-10 14:12:05