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

