There was an error while loading. Please reload this page.
2 parents f07a7b8 + f72c50c commit fc298e1Copy full SHA for fc298e1
1 file changed
leetcode3/남효정/3940. Limit Occurrences in Sorted Array.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def limitOccurrences(self, nums: list[int], k: int) -> list[int]:
3
+ num_type = sorted(list(set(nums)))
4
+ ans = []
5
+ for num in num_type:
6
+ num_cnt = nums.count(num)
7
+ if num_cnt > k:
8
+ ans += ([num] * k)
9
+ else:
10
+ ans += ([num] * num_cnt)
11
+ return ans
12
+
0 commit comments