1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
var twoSum = function(nums, target) { let [left, right] = [0, nums.length - 1];
while (right > 0 && right !== left) { if (nums[left] + nums[right] === target) { return [left, right]; }
if (right === left + 1) { left++; right = nums.length; }
right--; } };
|