-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsol.java
More file actions
34 lines (28 loc) · 750 Bytes
/
sol.java
File metadata and controls
34 lines (28 loc) · 750 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
31
32
33
34
public class Solution{
public static void main(String[] args) {
Solution1 test;
test = new Solution1();
System.out.println(test);
}
}
class Solution1 {
public int search(int[] nums, int target) {
if (nums.length == 0) {
return -1;
}
int left = 0;
int right = nums.length - 1;
System.out.println(right);
while (left <= right) {
int midpoint = (left + right) / 2;
if (nums[midpoint] == target) {
return midpoint;
} else if (nums[midpoint] > target) {
right = midpoint - 1;
} else {
left = midpoint + 1;
}
}
return -1;
}
}