【解题思路】
对houses[ ]、heaters[ ]进行排序,找到每一个房子距离最近的供暖器的距离,在这些距离中选择最大距离,即为供暖器的最小半径。
class Solution {
public int findRadius(int[] houses, int[] heaters) {
Arrays.sort(houses);
Arrays.sort(heaters);
long[] distance = new long[houses.length];
for(int i = 0; i < houses.length; i++)
{
long num = 999999999;
for(int j = 0; j < heaters.length; j++)
{
if(Math.abs(heaters[j] - houses[i]) < num)
{
num = Math.abs(heaters[j] - houses[i]);
}
}
distance[i] = num;
}
Arrays.sort(distance);
return (int)distance[houses.length-1];
}
}