-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
30 lines (29 loc) · 730 Bytes
/
Copy pathsolution.java
File metadata and controls
30 lines (29 loc) · 730 Bytes
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
30
// 167. Two Sum II - Input Array Is Sorted
// https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
// Medium | Java | Accepted 2024-09-08
// Runtime 2 ms | Memory 47.5 MB
class Solution {
public int[] twoSum(int[] numbers, int target) {
int i = 0;
int j = numbers.length-1;
int[] bruh = new int[2];
while(i<j)
{
if(numbers[i]+numbers[j]<target)
{
i++;
}
else if(numbers[i]+numbers[j]>target)
{
j--;
}
else
{
bruh[0] = i+1;
bruh[1] = j+1;
break;
}
}
return bruh;
}
}