Skip to content

Commit 2f6584c

Browse files
author
Fettes
committed
update problems
1 parent 6d98c92 commit 2f6584c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @lc app=leetcode id=167 lang=java
3+
*
4+
* [167] Two Sum II - Input array is sorted
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public int[] twoSum(int[] numbers, int target) {
10+
int start = 0;
11+
int end = numbers.length - 1;
12+
13+
while (start <= end) {
14+
int sum = numbers[start] + numbers[end];
15+
if (sum == target) {
16+
return new int[]{start + 1, end + 1};
17+
} else if (sum < target) {
18+
start++;
19+
} else {
20+
end--;
21+
}
22+
}
23+
return new int[]{-1, -1};
24+
}
25+
}
26+
// @lc code=end
27+

0 commit comments

Comments
 (0)