1128.Number of Equivalent Domino Pairs
1128.Number of Equivalent Domino Pairs
难度:Easy
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].
可以先按大小排个序,然后建立一个map,统计次数大于1的元素个数,每个元素的对数为C(2,n)
执行用时 :68 ms, 在所有 C++ 提交中击败了76.11%的用户 内存消耗 :23.5 MB, 在所有 C++ 提交中击败了100.00%的用户
Last updated