2250. Count Number of Rectangles Containing Each Point

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2250

class Solution:
    def countRectangles(
        self, rectangles: List[List[int]], points: List[List[int]]
    ) -> List[int]:
        d = defaultdict(list)
        for x, y in rectangles:
            d[y].append(x)
        for y in d.keys():
            d[y].sort()
        res = []
        for x, y in points:
            cnt = 0
            for h in range(y, 101):
                xs = d[h]
                cnt += len(xs) - bisect_left(xs, x)
            res.append(cnt)
        return res