LeetCode 167 Two Sum 2-Input array is sorted
2017-06-10 14:28
357 查看
LeetCode 167 Two Sum 2-Input array is sorted
#include <vector> using namespace std; class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { vector<int> result; int length = numbers.size(); int left = 0; int right = length - 1; int tmp = 0; while (left < right < length && numbers[left] <= target/2) { tmp = numbers[left] + numbers[right]; if (tmp < target) left ++; if (tmp == target) { result.push_back(left + 1); result.push_back(right + 1); return result; } if (tmp > target) right --; } } };
相关文章推荐
- LeetCode[167] Two Sum II - Input array is sorted
- [C语言][LeetCode][167]Two Sum II - Input array is sorted
- Leetcode 167 Two Sum II - Input array is sorted
- leetcode-167-Input array is sorted
- Leetcode 167 Two Sum II - Input array is sorted
- LeetCode 167 Two Sum II - Input array is sorted (两点法)
- [LeetCode]167 Two Sum II - Input array is sorted
- leetcode 167 Two Sum II - Input array is sorted C++
- Leetcode #167 Two Sum II - Input array is sorted
- LeetCode 167: Two Sum II - Input array is sorted
- leetcode[167]Two Sum II - Input array is sorted
- Leetcode #167 Two Sum II - Input array is sorted
- leetcode 167 Two Sum II - Input array is sorted
- leetcode167: Two Sum II - Input array is sorted
- leetcode[167] Two Sum II - Input array is sorted
- Leetcode 167 Two Sum II - Input array is sorted
- LeetCode 167:Two Sum II - Input array is sorted
- leetcode note--leetcode 167 Two Sum II - Input array is sorted
- leetcode167~Two Sum II - Input array is sorted
- [leetcode 167] Two Sum II - Input array is sorted