17 lines
476 B
Python
17 lines
476 B
Python
# https://leetcode.com/problems/number-of-equivalent-domino-pairs
|
|
|
|
from typing import Dict, List, Tuple
|
|
|
|
class Solution:
|
|
def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
|
|
m: Dict[Tuple[int, int], int] = {}
|
|
result = 0
|
|
for [v1, v2] in dominoes:
|
|
t = (v1, v2)
|
|
if v2 > v1:
|
|
t = (v2, v1)
|
|
if t in m:
|
|
result += m[t]
|
|
m[t] = m.get(t, 0) + 1
|
|
return result
|
|
|