Description
Submission
class Solution { int comb2(int n) { return n * (n - 1) / 2; } public: int numIdenticalPairs(vector<int>& nums) { map<int, int> cnt; for(int x: nums) { cnt[x]++; } map<int, int> occur; int ret = 0; for(auto p: cnt) { ret += comb2(p.second); } return ret; } };