Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created August 13, 2018 13:30
Show Gist options
  • Save luojiyin1987/0360a6f9fc23e6cbf76482f870976418 to your computer and use it in GitHub Desktop.
Save luojiyin1987/0360a6f9fc23e6cbf76482f870976418 to your computer and use it in GitHub Desktop.
Heaters
class Solution:
def findRadius(self, houses, heaters):
"""
:type houses: List[int]
:type heaters: List[int]
:rtype: int
"""
ans = 0
heaters.sort()
for house in houses:
radius = 0x7FFFFFFF
le = bisect.bisect_right(heaters, house)
if le > 0:
radius = min(radius, house - heaters[le - 1])
ge = bisect.bisect_left(heaters, house)
if ge < len(heaters):
radius = min(radius, heaters[ge] - house)
ans = max(ans, radius)
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment