Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Feb 7, 2025
1 parent 2184186 commit 2556d71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions leetcode/daily/3160/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// https://leetcode.com/problems/find-the-number-of-distinct-colors-among-the-balls/
package main

func queryResults(limit int, queries [][]int) (ans []int) {
g := map[int]int{}
cnt := map[int]int{}
for _, q := range queries {
x, y := q[0], q[1]
cnt[y]++
if v, ok := g[x]; ok {
cnt[v]--
if cnt[v] == 0 {
delete(cnt, v)
}
}
g[x] = y
ans = append(ans, len(cnt))
}
return
}

func main() {
queries := [][]int{{1, 4}, {2, 5}, {1, 3}, {3, 4}}
limit := 4
println(queryResults(limit, queries))
}

0 comments on commit 2556d71

Please sign in to comment.