-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path475.txt
More file actions
30 lines (28 loc) · 708 Bytes
/
Copy path475.txt
File metadata and controls
30 lines (28 loc) · 708 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
class Solution {
public int findRadius(int[] houses, int[] heaters) {
Arrays.sort(houses);
Arrays.sort(heaters);
int l=0,r=2000000000;
int res=0;
while(l<=r){
int mid=l+(r-l)/2;
if(check(houses,heaters,mid)){
res=mid;
r=mid-1;
}else{
l=mid+1;
}
}
return res;
}
public boolean check(int A[],int B[],int mid){
int j=0;
for(int i=0;i<A.length;i++){
while(A[i]<B[j]-mid||A[i]>B[j]+mid){
j++;
if(j>=B.length)return false;
}
}
return true;
}
}