This commit is contained in:
parent
dd5dcd1f20
commit
3b8054ba50
1 changed files with 17 additions and 0 deletions
17
easy/number_of_equivalent_domino_pairs.py
Normal file
17
easy/number_of_equivalent_domino_pairs.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue