[LeetCode] Number of Equivalent Domino Pairs

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

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int numEquivDominoPairs(vector<vector<int>>& dominoes) {
map<pair<int,int>,int> mp;
int res = 0;
for(auto& d : dominoes) {
pair<int,int> p{min(d[0],d[1]),max(d[0],d[1])};
res += mp[p]++;
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/05/04/PS/LeetCode/number-of-equivalent-domino-pairs/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.