Commit b11e07ee by bonnieyan

提交作业

parent 597c7e71
#
#
# class Solution(object):
#
# def find_radius(self, house, heaters):
#
#
#
# su = Solution()
# su.find_radius([1, 2, 3, 4], [1, 4])
class Heater:
def findRadius(self, houses, heaters):
heaters.sort()
houses.sort()
radius = 0
i = 0
# 哨兵
heaters = [-1] + heaters + [float('inf')]
for house in houses:
while house > heaters[i]:
i = i + 1
current_radius = min(house - heaters[i - 1], heaters[i] - house)
radius = max(radius, current_radius)
return radius
h = Heater()
result = h.findRadius([1, 2, 3, 4, 6], [1, 4])
print(result)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment