题解 | #和为S的两个数字#
和为S的两个数字
http://www.nowcoder.com/practice/390da4f7a00f44bea7c2f3d19491311b
class Solution {
public:
vector<int> FindNumbersWithSum(vector<int> array,int sum) {
int i = 0, j = array.size() - 1;
while (i < j) {
if (array[i] + array[j] == sum) {
return {array[i], array[j]};
} else if (array[i] + array[j] > sum) {
j--;
} else {
i++;
}
}
return {};
}
};