LC : https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/
    牛客:https://www.nowcoder.com/practice/390da4f7a00f44bea7c2f3d19491311b?tpId=13&&tqId=11195&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

    1. 双指针,一个从左,一个从右遍历,两数之和大于target 的话 right--, 两数之和小于target的话 left++
    1. class Solution {
    2. public:
    3. vector<int> twoSum(vector<int> &nums, int target) {
    4. int left = 0, right = nums.size() - 1;
    5. while (left < right) {
    6. int calc = nums[left] + nums[right];
    7. if (calc == target) {
    8. return vector<int>{nums[left], nums[right]};
    9. } else if (calc > target) {
    10. right--;
    11. } else {
    12. left++;
    13. }
    14. }
    15. return vector<int>{-1, -1};
    16. }
    17. };