There was an error while loading. Please reload this page.
1 parent 95357fa commit dbdff9aCopy full SHA for dbdff9a
1 file changed
leetcode3/최원준/3940. Limit Occurrences in Sorted Array.py
@@ -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