Last active
July 29, 2019 06:46
-
-
Save Alfons0329/4825d4fd9366298e0735f23e6e1196aa to your computer and use it in GitHub Desktop.
LeetCode_1128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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