diff --git "a/leetcode3/\353\202\250\355\232\250\354\240\225/3940. Limit Occurrences in Sorted Array.py" "b/leetcode3/\353\202\250\355\232\250\354\240\225/3940. Limit Occurrences in Sorted Array.py" new file mode 100644 index 00000000..6951dd11 --- /dev/null +++ "b/leetcode3/\353\202\250\355\232\250\354\240\225/3940. Limit Occurrences in Sorted Array.py" @@ -0,0 +1,12 @@ +class Solution: + def limitOccurrences(self, nums: list[int], k: int) -> list[int]: + num_type = sorted(list(set(nums))) + ans = [] + for num in num_type: + num_cnt = nums.count(num) + if num_cnt > k: + ans += ([num] * k) + else: + ans += ([num] * num_cnt) + return ans + \ No newline at end of file