2001. Number of Pairs of Interchangeable Rectangles
On This Page
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