Files
2020-08-09 00:39:24 +08:00

38 lines
1.6 KiB
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [1128. Number of Equivalent Domino Pairs](https://leetcode.com/problems/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]`.
**Example 1:**
Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
Output: 1
**Constraints:**
- `1 <= dominoes.length <= 40000`
- `1 <= 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 <= dominoes.length <= 40000
- 1 <= dominoes[i][j] <= 9
## 解题思路
- 给出一组多米诺骨牌求出这组牌中相同牌的个数牌相同的定义是牌的 2 个数字相同(正序或者逆序相同都算相同)
- 简单题由于牌是 2 个数所以将牌的 2 个数 hash 成一个 2 位数比较大小即可正序和逆序都 hash 2 位数然后在桶中比较是否已经存在如果不存在跳过如果存在计数