Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
heaters.py 799 Bytes
一键复制 编辑 原始数据 按行查看 历史
Allen Liu 提交于 2018-10-13 01:56 +08:00 . add complexity
# Time: O((m + n) * logn), m is the number of the houses, n is the number of the heaters.
# Space: O(1)
import bisect
class Solution(object):
def findRadius(self, houses, heaters):
"""
:type houses: List[int]
:type heaters: List[int]
:rtype: int
"""
heaters.sort()
min_radius = 0
for house in houses:
equal_or_larger = bisect.bisect_left(heaters, house)
curr_radius = float("inf")
if equal_or_larger != len(heaters):
curr_radius = heaters[equal_or_larger] - house
if equal_or_larger != 0:
smaller = equal_or_larger-1
curr_radius = min(curr_radius, house - heaters[smaller])
min_radius = max(min_radius, curr_radius)
return min_radius
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助