题解 | #和为S的两个数字#
和为S的两个数字
https://www.nowcoder.com/practice/390da4f7a00f44bea7c2f3d19491311b
function FindNumbersWithSum(array, sum) { // write code here let left = 0 let right = array.length - 1 while (left < right) { if (array[left] + array[right] < sum) { left++ } else if (array[left] + array[right] > sum) { right-- } else { return [array[left], array[right]] } } return [] } module.exports = { FindNumbersWithSum : FindNumbersWithSum };