2001. Number of Pairs of Interchangeable Rectangles

Updated: 2024-03-12
1 min read
[]

On This Page

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