Skip to content

Commit

Permalink
Time: 185 ms (57.14%), Space: 68.1 MB (37.46%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
gkapelyushok committed May 4, 2022
1 parent a6131bc commit a20f8c6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 1679-max-number-of-k-sum-pairs/1679-max-number-of-k-sum-pairs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
int maxOperations(vector<int>& nums, int k) {
int count = 0;
unordered_map<int, int> map;
for (int i : nums) {
int res = k - i;
if (map.count(res)) {
if (map[res] == 1) {
map.erase(res);
} else {
map[res]--;
}
count++;
} else {
map[i]++;
}
}
return count;
}
};

0 comments on commit a20f8c6

Please sign in to comment.