Re: [閒聊] 每日leetcode

作者: dont   2025-02-07 21:43:23
3160. Find the Number of Distinct Colors Among the Balls
## 思路
兩個hash map
一個紀錄球的顏色, 一個紀錄每種顏色的個數
每次QUERY更新兩個map
如果球顏色改變, 就減掉原本顏色個數
## Code
```cpp
class Solution {
public:
vector<int> queryResults(int limit, vector<vector<int>>& queries) {
unordered_map<int, int> balls;
unordered_map<int, int> counter;
vector<int> res;
for (auto& query: queries) {
int b=query[0], c=query[1];
if (balls.find(b) != balls.end()) {
if (

Links booklink

Contact Us: admin [ a t ] ucptt.com