- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSumII.java
More file actions
Latest commit
19 lines (19 loc) · 561 Bytes
/
Copy pathTwoSumII.java
File metadata and controls
19 lines (19 loc) · 561 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
publicclassTwoSumII {
publicint[] twoSum(int[] numbers, inttarget) {
intleft = 0;
intright = numbers.length - 1;
while (left < right) {
if (numbers[left] + numbers[right] == target) {
returnnewint[] {left+1, right+1};
}
if (numbers[right] > target) {
right--;
} elseif (numbers[left] + numbers[right] < target) {
left++;
} else {
right--;
}
}
returnnewint[] {};
}
}