2001. Number of Pairs of Interchangeable Rectangles

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

Содержание

LeetCode problem 2001

class Solution:
    def interchangeableRectangles(self, rectangles: List[List[int]]) -> int:
        res = 0
        cnt = Counter()
        for w, h in rectangles:
            g = gcd(w, h)
            w, h = w // g, h // g
            res += cnt[(w, h)]
            cnt[(w, h)] += 1
        return res