-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeb_3_Leetcode.java
More file actions
37 lines (30 loc) · 846 Bytes
/
Feb_3_Leetcode.java
File metadata and controls
37 lines (30 loc) · 846 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
35
36
37
package Daily_Problem;
public class Feb_3_Leetcode {
public static void main(String[] args) {
int[] arr= {12,33,44,355,535,555,664,757,888};
int target=663;
System.out.println(ceiling(arr,target));
}
static int ceiling(int arr[], int target) {
int start = 0;
int end = arr.length - 1;
while (start <= end) {
int mid = start + (end - start) / 2;
if (arr[mid] == target)
return mid;
boolean isAs = arr[start] < arr[mid];
if (isAs) {
if (arr[mid] < target)
start = mid + 1;
else
end = mid - 1;
} else {
if (arr[mid] > target)
start = mid + 1;
else
end = mid - 1;
}
}
return start;
}
}