1.题目
2.算法
方法一,我们可以找距离每个房子的最近的暖气,然后找出他们的最大值
public int findRadius(int[] houses, int[] heaters)
{
Arrays.sort(heaters);
int maxL = 0;
for (int i = 0; i < houses.length; i++)
{
int index = Arrays.binarySearch(heaters, houses[i]);
if (index < 0)
{
index = ~index;
int minL = index - 1 >= 0 ? houses[i] - heaters[index - 1]:Integer.MAX_VALUE;
int minR = index < heaters.length ? heaters[index] - houses[i] : Integer.MAX_VALUE;
maxL = Math.max(maxL, Math.min(minL, minR));
}
}
return maxL;
}