Created
August 13, 2018 13:30
-
-
Save luojiyin1987/0360a6f9fc23e6cbf76482f870976418 to your computer and use it in GitHub Desktop.
Heaters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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