Given a list of
dominoes,dominoes[i] = [a, b]is equivalent todominoes[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 which0 <= i < j < dominoes.length, anddominoes[i]is equivalent todominoes[j].
1 | Input: dominoes = [[1,2],[2,1],[3,4],[5,6]] |
Constraints:
1 <= dominoes.length <= 400001 <= dominoes[i][j] <= 9给你一个由一些多米诺骨牌组成的列表 dominoes。
如果其中某一张多米诺骨牌可以通过旋转 0 度或 180 度得到另一张多米诺骨牌,我们就认为这两张牌是等价的。
形式上,dominoes[i] = [a, b] 和 dominoes[j] = [c, d] 等价的前提是 a==c 且 b==d,或是a==d 且b==c。
在 0 <= i < j < dominoes.length的前提下,找出满足 dominoes[i] 和 dominoes[j]等价的骨牌对(i, j) 的数量。
找出类似[1,2]和[2,1]这种形式对称的骨牌对数,即满足[a,b]和[c,d]中,a==c和 b==d
提示指出dominoes.length在1到4w间,且骨牌的点数在1到9之间。故所有骨牌的种类只有81种,可以建立一个10*10(忽略下标为0)的二维数组,暴力遍历统计所有骨牌种类的数量,每种骨牌中相互组合的对数即为该种骨牌满足条件的对数。
1 | class { |
总结:
原文:https://www.cnblogs.com/lijianming180/p/12410257.html