LeetCode——1128. 等价多米诺骨牌对的数量
作者:互联网
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题重拳出击
标签:1128,多米诺骨牌,int,List,numEquivDominoPairs,dominoes,return,LeetCode 来源: https://blog.csdn.net/weixin_37724529/article/details/113172873