Skip to content

Commit 5368227

Browse files
committed
Time: 3 ms (28.34%), Space: 50 MB (29.33%) - LeetHub
1 parent 7c47804 commit 5368227

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int[] twoSum(int[] numbers, int target) {
3+
int l = 0;
4+
int r = numbers.length -1;
5+
6+
while(l < r) {
7+
int sum = numbers[l] + numbers[r];
8+
9+
if(sum > target) {
10+
r = r - 1;
11+
}else if(sum < target) {
12+
l = l + 1;
13+
}else{
14+
return new int[]{ l +1, r +1 };
15+
}
16+
}
17+
return null;
18+
19+
}
20+
}

0 commit comments

Comments
 (0)