Skip to content

Commit fc9bd24

Browse files
authored
Merge pull request neetcode-gh#888 from Vitali-Matteo/patch-2
Create 1512-Number-Of-Good-Pairs.cpp
2 parents 64a01e6 + d4637e5 commit fc9bd24

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cpp/1512-Number-Of-Good-Pairs.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
unordered_map<int, int> Memo = {};
3+
int numIdenticalPairs(vector<int> & nums){
4+
unordered_map<int, int> Memo;
5+
int i, k;
6+
int NGood;
7+
NGood = 0;
8+
Memo = {};
9+
for(int & i : nums){
10+
if(Memo.find(i) == Memo.end()){
11+
Memo.insert(make_pair(i, 1));
12+
}
13+
else{
14+
NGood = NGood + Memo[i];
15+
Memo[i]++;
16+
}
17+
}
18+
return NGood;
19+
}
20+
};

0 commit comments

Comments
 (0)