Skip to content

Commit 2556d71

Browse files
committed
add sol
1 parent 2184186 commit 2556d71

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

leetcode/daily/3160/sol.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://leetcode.com/problems/find-the-number-of-distinct-colors-among-the-balls/
2+
package main
3+
4+
func queryResults(limit int, queries [][]int) (ans []int) {
5+
g := map[int]int{}
6+
cnt := map[int]int{}
7+
for _, q := range queries {
8+
x, y := q[0], q[1]
9+
cnt[y]++
10+
if v, ok := g[x]; ok {
11+
cnt[v]--
12+
if cnt[v] == 0 {
13+
delete(cnt, v)
14+
}
15+
}
16+
g[x] = y
17+
ans = append(ans, len(cnt))
18+
}
19+
return
20+
}
21+
22+
func main() {
23+
queries := [][]int{{1, 4}, {2, 5}, {1, 3}, {3, 4}}
24+
limit := 4
25+
println(queryResults(limit, queries))
26+
}

0 commit comments

Comments
 (0)