Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 914 Bytes

1620.md

File metadata and controls

28 lines (26 loc) · 914 Bytes

1620. Coordinate With Maximum Network Quality

Solution 1 (time O(x_maxy_maxn), space O(1))

class Solution(object):
    def bestCoordinate(self, towers, radius):
        """
        :type towers: List[List[int]]
        :type radius: int
        :rtype: List[int]
        """
        x_max = max(t[0] for t in towers)
        y_max = max(t[1] for t in towers)
        max_quality = -float("inf")
        max_pos = [-1, -1]
        for x in range(x_max + 1):
            for y in range(y_max + 1):
                quality = 0
                for tx, ty, q in towers:
                    d = (x - tx) ** 2 + (y - ty) ** 2
                    if d <= radius ** 2:
                        quality += int(q / (1 + d ** 0.5))
                if quality > max_quality:
                    max_quality = quality
                    max_pos = [x, y]
        return max_pos