var twoSum = function(nums, target) { var obj = {} var i = 0 var res = [] while (i < nums.length) { if(obj[target - nums[i]] !== undefined) { res.push(obj[target - nums[i]]) res.push(i) } else { obj[nums[i]] = i } i++ } return res };
2022-09-24 10:48:33
var twoSum = function(nums, target) { var obj = {} var i = 0 var res = [] while (i < nums.length) { if(obj[target - nums[i]] !== undefined) { res.push(obj[target - nums[i]]) res.push(i) } else { obj[nums[i]] = i } i++ } return res };