-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbque5.java
40 lines (37 loc) · 1.06 KB
/
bque5.java
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
38
39
40
package binarysearch;
public class bque5 {
static boolean findDuplicateTarget(int a[],int target){
int n=a.length;
int st=0,end=n - 1;
while (st<=end) {
int mid = st + (end - st)/2;
if (a[mid] == target) return true;
if (a[mid] == a[st] && a[mid] == a[end]) {
st++;
end--;
}
else if (a[mid]<=a[end]) {
//mid to end sorted
if (target >a[mid] && target <= a[end]) {
st = mid + 1;
}
else{
end = mid - 1;
}
}
else {
if (target < a[mid] && target >= a[st]) {
end = mid - 1;
}
else{
st = mid + 1;
}
}
}
return false;
}
public static void main(String[] args) {
int a[]={1,1,1,2,3,3,3,1,1,1};
System.out.println(findDuplicateTarget(a,4));
}
}