Python Solution (Max-Min problem)


  • 0
    S
    import bisect
    
    
    class Solution(object):
        def findRadius(self, houses, heaters):
            """
            :type houses: List[int]
            :type heaters: List[int]
            :rtype: int
            """
            houses = sorted(houses)
            heaters = sorted(heaters)
    
            H, res = len(heaters), 0
            for house in houses:
                i = bisect.bisect_left(heaters, house, 0, H - 1)
                if heaters[i] != house:
                    res = max(res, min(abs(house - heaters[i - 1]), abs(house - heaters[i])))
    
            return res

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.