对于每个房屋,要么用前面的暖气,要么用后面的,二者取近的,得到距离;
对于所有的房屋,选择最大的上述距离
class Solution {
public int findRadius(int[] houses, int[] heaters) {
Arrays.sort(houses); Arrays.sort(heaters);
int result = 0;
for(int i = 0, j = 0; i < houses.length; i++){
int current = Math.abs(houses[i] - heaters[j]);
while(j < heaters.length - 1 && current >= Math.abs(houses[i] - heaters[j + 1])){
current = Math.min(current, Math.abs(houses[i] - heaters[++j]));
}
result = Math.max(result,current);
}
return result;
}
}