- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo695.java
29 lines (28 loc) · 530 Bytes
/
No695.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
packageAlgorithm.leetcode.Array;
/**
*
* Created by tujietg on Nov 6, 2019
*/
publicclassNo695 {
publicint[] twoSum(int[] numbers, inttarget) {
int[] end = newint[2];
if (numbers.length < 2) {
returnend;
}
intleft = 0;
intright = numbers.length - 1;
while (left < right) {
intnum = numbers[left] + numbers[right];
if (num == target) {
end[0] = left + 1;
end[1] = right + 1;
returnend;
} elseif (num > target) {
right--;
} else {
left++;
}
}
returnend;
}
}