Skip to content

Instantly share code, notes, and snippets.

@Alfons0329
Last active July 29, 2019 06:46
Show Gist options
  • Save Alfons0329/4825d4fd9366298e0735f23e6e1196aa to your computer and use it in GitHub Desktop.
Save Alfons0329/4825d4fd9366298e0735f23e6e1196aa to your computer and use it in GitHub Desktop.
LeetCode_1128
class Solution {
public:
int numEquivDominoPairs(vector<vector<int>>& d)
{
int res = 0, n = d.size();
map<pair<int, int>, int> m;
for(int i = 0; i < n; i++)
{
if(d[i][0] > d[i][1])
{
m[make_pair(d[i][1], d[i][0])]++;
}
else
{
m[make_pair(d[i][0], d[i][1])]++;
}
}
auto it = m.begin();
while(it != m.end())
{
if(it -> second > 1)
{
res += (it -> second) * (it -> second - 1) / 2 ;
}
it++;
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment