-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (28 loc) · 865 Bytes
/
Solution.java
File metadata and controls
32 lines (28 loc) · 865 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
public class Solution{
public int guessNumber(int n) {
long low=1;
long high=n;
int count=0;
long mid=0;
mid=low+(high-low)/2;
System.out.println("MID:- "+mid);
while(mid>=0 && low<=high){
System.out.println("LOW:- "+low);
System.out.println("HIGH:- "+high);
mid=(low+high)/2;
System.out.println("MID:- "+mid);
int result=guess((int)mid);
System.out.println("RESULT:- "+result);
if(result==-1){
high=mid-1;
// System.out.println("HIGH:- "+high);
}else if(result==1){
low=mid+1;
// System.out.println("LOW:- "+low);
}else{
return (int)mid;
}
}
return 1;
}
}