> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/1128.number_of_equivalent_domino_pairs.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
