LeetCode:Two Sum II

 public class Solution {
public int[] twoSum(int[] numbers, int target) {
int left = 0;
int right = numbers.length - 1;
while (left < right) {
int sum = numbers[left] + numbers[right];
if (sum == target) {
return new int[]{left + 1, right + 1};
}
else if (sum < target) {
left++;
}
else right--;
}
return new int[]{0, 0};
}
}
上一篇:Android 之 ListView的学习


下一篇:基于OpenCV.Net连通域分析进行文本块分割