forked from Manish57-droid/python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceiling in java.java
More file actions
Latest commit
27 lines (26 loc) · 725 Bytes
/
Copy pathceiling in java.java
File metadata and controls
27 lines (26 loc) · 725 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
publicclassCeiling {
publicstaticvoidmain(String[] args) {
int[] arr = {1,3,7,9,14,20,26,29};
inttarget = 25;
intans = ceiling(arr, target);
System.out.println(ans);
}
staticintceiling(int[] arr, inttarget) {
if (target > arr[arr.length - 1]) {
return -1;
}
intstart = 0;
intend = arr.length - 1;
while(start <= end) {
intmid = start + (end - start) / 2;
if (target < arr[mid]) {
end = mid - 1;
} elseif (target > arr[mid]) {
start = mid + 1;
} else {
returnmid;
}
}
returnstart;
}
}