## 题目描述：

LeetCode 475. Heaters

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 are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all houses could be covered by those heaters.

So, your input will be the positions of houses and heaters seperately, and your expected output will be the minimum radius standard of heaters.

Note:

1. Numbers of houses and heaters you are given are non-negative and will not exceed 25000.
2. Positions of houses and heaters you are given are non-negative and will not exceed 10^9.
3. As long as a house is in the heaters' warm radius range, it can be warmed.

Example 1:

```Input: [1,2,3],[2]

Output: 1

Explanation: The only heater was placed in the position 2, and if we use the radius 1 standard, then all the houses can be warmed.```

Example 2:

```Input: [1,2,3,4],[1,4]

Output: 1

Explanation: The two heater was placed in the position 1 and 4. We need to use radius 2 standard, then all the houses can be warmed.```

## 题目大意：

1. 房屋和加热器的数目均为非负整数，并且不大于25000
2. 房屋和加热器的位置是非负整数，并且不超过10^9
3. 位于加热器半径范围内的房屋均可被加热
4. 加热器的半径都是一样的

## 解题思路：

```升序排列加热器的坐标heaters

利用二分查找，分别找到不大于house的最大加热器坐标left，以及不小于house的最小加热器坐标right

则当前房屋所需的最小加热器半径radius = min(house - left, right - house)

## Python代码：

``````class Solution(object):
"""
:type houses: List[int]
:type heaters: List[int]
:rtype: int
"""
ans = 0
heaters.sort()
for house in houses:
le = bisect.bisect_right(heaters, house)
if le > 0:
ge = bisect.bisect_left(heaters, house)
if ge < len(heaters):
return ans
``````

Pingbacks已关闭。