Maximum Number of Pairs in Array LeetCode solution in C++

1
class Solution {
2
public:
3
// store the frequency of each of the number in the map and
4
// then return the answer as sum all the values dividing 2 and
5
// sum all by taking reminder of 2
6
vector<int> numberOfPairs(vector<int> &nums) {
7
unordered_map<int, int> mp;
8
for (auto i : nums) mp[i]++;
9
int c1 = 0, c2 = 0;
10
for (auto m : mp) {
11
c1 += m.second / 2;
12
c2 += m.second % 2;
13
}
14
return {c1, c2};
15
}
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0