Skip to content

Commit dbdff9a

Browse files
authored
Create 3940. Limit Occurrences in Sorted Array.py
1 parent 95357fa commit dbdff9a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from collections import defaultdict
2+
class Solution:
3+
def limitOccurrences(self, nums: list[int], k: int) -> list[int]:
4+
counter = defaultdict(int)
5+
ans = []
6+
for num in nums:
7+
if counter[num] == k:
8+
continue
9+
counter[num]+=1
10+
ans.append(num)
11+
12+
return ans

0 commit comments

Comments
 (0)