This commit is contained in:
parent
75543f2df6
commit
351207504c
1 changed files with 20 additions and 0 deletions
20
medium/find_the_number_of_distinct_colors_among_the_balls.py
Normal file
20
medium/find_the_number_of_distinct_colors_among_the_balls.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# https://leetcode.com/problems/find-the-number-of-distinct-colors-among-the-balls
|
||||||
|
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def queryResults(self, _: int, queries: List[List[int]]) -> List[int]:
|
||||||
|
balls: Dict[int, int] = {}
|
||||||
|
colors: Dict[int, int] = {}
|
||||||
|
result = []
|
||||||
|
for [ball, color] in queries:
|
||||||
|
curr_color = balls.get(ball, 0)
|
||||||
|
if curr_color != 0:
|
||||||
|
colors[curr_color] -= 1
|
||||||
|
if colors[curr_color] == 0:
|
||||||
|
del(colors[curr_color])
|
||||||
|
balls[ball] = color
|
||||||
|
colors[color] = colors.get(color, 0) + 1
|
||||||
|
result.append(len(colors))
|
||||||
|
|
||||||
|
return result
|
||||||
Loading…
Add table
Add a link
Reference in a new issue