Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.
Now, you is given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so it all HO Uses could is covered by those heaters.
So, your input would be the positions of houses and heaters seperately, and your expected output would be the minimum radius Standard of heaters.
Example 1:
Input: [1,2,3],[2]output:1explanation:the only heater is placed in the position 2, and if we use the radius 1, Then all the houses can warmed.
Example 2:
Input: [1,2,3,4],[1,4]output:1explanation:the heater is placed in the position 1 and 4. We need to use RADIUS 1 standard and then all the houses can is warmed.
According to the requirements of the topic, is to place the stove on the heaters, covering all the houses, to find the maximum radius of the nearest stove.
idea: A house can choose two stoves. To the left and to the right, which distance oneself near, choose to be which stove warm, notice the first heater left houses can only be the first heater warm, the last heater right of the
houses can only be the last heater warm, the rest of the Middle House, Can be left and right at the same time warm, in all the nearest radius to choose the largest radius, is the problem of the radius of the request.
Java code:
public class Solution {public int Findradius (int[] houses, int[] heaters) { arrays.sort (houses); Arrays.sort (heaters); int max=0; for (int i=0;i
475.Heaters Java