1128. Number of Equivalent Domino Pairs
Posted whatyouthink
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1128. Number of Equivalent Domino Pairs相关的知识,希望对你有一定的参考价值。
Given a list of dominoes
, dominoes[i] = [a, b]
is equivalent to dominoes[j] = [c, d]
if and only if either (a==c
and b==d
), or (a==d
and b==c
) - that is, one domino can be rotated to be equal to another domino.
Return the number of pairs (i, j)
for which 0 <= i < j < dominoes.length
, and dominoes[i]
is equivalent to dominoes[j]
.
Constraints:
1 <= dominoes.length <= 40000
1 <= dominoes[i][j] <= 9
因为数字范围是1-9,所以两位我打算把他们两两排序然后x*10+y拼成两位数,然后用一个计数数组存出现的次数
class Solution(object): def numEquivDominoPairs(self, dominoes): """ :type dominoes: List[List[int]] :rtype: int """ d = [0] * 100 ans = 0 for dominoe in dominoes: x = min(dominoe[0], dominoe[1]) y = max(dominoe[0], dominoe[1]) ans += d[x * 10 + y] d[x * 10 + y] += 1 return ans
以上是关于1128. Number of Equivalent Domino Pairs的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode --- 1128. Number of Equivalent Domino Pairs 解题报告
LeetCode --- 1128. Number of Equivalent Domino Pairs 解题报告
[LeetCode] 1128. Number of Equivalent Domino Pairs 等价多米诺骨牌对的数量
*Find the Number Occurring Odd Number of Times
tne number which is made of the number of remaining is smallest
ValueError: The number of elements in ‘fill‘ does not match the number of bands of the image (3 != 4