class Solution:
def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:
if not dominoes:
return 0
dic = defaultdict(int)
for x,y in dominoes:
if x<y:
dic[(x,y)]+=1
else:
dic[(y,x)]+=1
res = 0
for k,v in dic.items():
tmp = (v*(v-1))//2
res+=tmp
return res
- 利用hash表存储出现的次数
- 然后计算有多少对即可
- easy题重拳出击