Leetcode 1227 Solution

This article provides solution to leetcode question 1227 (number-of-equivalent-domino-pairs)

https://leetcode.com/problems/number-of-equivalent-domino-pairs

Solution

class Solution:
    def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
        a = {}

        res = 0
        for domino in dominoes:
            min_val = min(domino[0], domino[1])
            max_val = max(domino[0], domino[1])

            k = (min_val, max_val)

            if k not in a:
                a[k] = 0

            old_cnt = a[k]
            res += old_cnt

            a[k] += 1

        return res