Open fly0o0 opened 4 years ago
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
let sum = 0
let start = 0
let end = nums.length - 1
while (start < end) {
sum = nums[end] + nums[start]
if (sum === target) {
return [nums[start], nums[end]]
}
if (sum > target) {
end--
} else {
start++
}
}
return []
};