# 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].

```
Example 1:

Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
Output: 1
 

Constraints:

1 <= dominoes.length <= 40000
1 <= dominoes[i][j] <= 9
```

可以先按大小排个序，然后建立一个map，统计次数大于1的元素个数，每个元素的对数为C(2,n)

```
class Solution {
public:
    int numEquivDominoPairs(vector<vector<int>>& dominoes) {
        int res=0;
        if(dominoes.size()<2) return res;
        for(auto &v: dominoes)
            if(v[0]>v[1]) swap(v[0],v[1]);
        map<vector<int>, int> domin_map;
        for(auto v:dominoes)
            domin_map[v]++;
        for(auto v:domin_map)
            if(v.second >1) res+= v.second * (v.second -1);
        return res/2;
        
            
        
    }
};
```

> 执行用时 :68 ms, 在所有 C++ 提交中击败了76.11%的用户\
> 内存消耗 :23.5 MB, 在所有 C++ 提交中击败了100.00%的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/1128.number_of_equivalent_domino_pairs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
