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};
}
}
相关文章
- 02-10LeetCode 课程表II(拓扑排序)
- 02-10[LeetCode] Course Schedule II
- 02-10LeetCode-210. Course Schedule II
- 02-10leetcode 54. Spiral Matrix 、59. Spiral Matrix II
- 02-10leetcode 62. Unique Paths 、63. Unique Paths II
- 02-10LeetCode: Sum Root to Leaf Numbers [129]
- 02-10Leetcode Sum Root to Leaf Numbers
- 02-10[Leetcode] Sum root to leaf numbers求根到叶节点的数字之和
- 02-10LeetCode :: Sum Root to Leaf Numbers [tree、dfs]
- 02-10Sum Root to Leaf Numbers——LeetCode