Skip to content

Commit

Permalink
Create 3160. Find the Number of Distinct Colors Among the Balls (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Feb 7, 2025
2 parents 5a20532 + a083372 commit 0a1b5bd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 3160. Find the Number of Distinct Colors Among the Balls
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
vector<int> queryResults(int limit, vector<vector<int>>& queries) {
int n = queries.size();
vector<int> res(n, -1);
unordered_map<int, int> colormp;
unordered_map<int, int> ballmp;

for (int i = 0; i < n; i++) {
int ball = queries[i][0];
int color = queries[i][1];
if (ballmp.find(ball) != ballmp.end()) {
int prevcolor = ballmp[ball];
colormp[prevcolor]--;
if (colormp[prevcolor] == 0) {
colormp.erase(prevcolor);
}
}
ballmp[ball] = color;
colormp[color]++;
res[i] = colormp.size();
}
return res;
}
};

0 comments on commit 0a1b5bd

Please sign in to comment.