Skip to content

Commit 7f55ee3

Browse files
committed
Feb 7
1 parent 11de539 commit 7f55ee3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def queryResults(self, _: int, queries: list[list[int]]) -> list[int]:
3+
ball_color = dict()
4+
color_count = dict()
5+
result = []
6+
for ball, color in queries:
7+
if ball in ball_color:
8+
color_count[ball_color[ball]] -= 1
9+
if color_count[ball_color[ball]] == 0:
10+
del color_count[ball_color[ball]]
11+
ball_color[ball] = color
12+
color_count[color] = color_count.get(color, 0) + 1
13+
result.append(len(color_count))
14+
return result
15+
16+
17+
def main():
18+
limit = 4
19+
queries = [[1, 4], [2, 5], [1, 3], [3, 4]]
20+
assert Solution().queryResults(limit, queries) == [1, 2, 2, 3]
21+
22+
limit = 4
23+
queries = [[0, 1], [1, 2], [2, 2], [3, 4], [4, 5]]
24+
assert Solution().queryResults(limit, queries) == [1, 2, 2, 3, 4]
25+
26+
27+
if __name__ == '__main__':
28+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| February 04 | [1800. Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum/) | Easy | Solved |
1111
| February 05 | [1790. Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/) | Easy | Solved |
1212
| February 06 | [1726. Tuple with Same Product](https://leetcode.com/problems/tuple-with-same-product/) | Medium | Solved |
13-
| February 07 | []() | | |
13+
| February 07 | [3160. Find the Number of Distinct Colors Among the Balls](https://leetcode.com/problems/find-the-number-of-distinct-colors-among-the-balls/) | Medium | Solved |
1414
| February 08 | []() | | |
1515
| February 09 | []() | | |
1616
| February 10 | []() | | |
@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 5 | 5 | 0 |
41-
| Medium | 1 | 1 | 0 |
41+
| Medium | 2 | 2 | 0 |
4242
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)