From f72c50cd8651e38655e0f50474461745f48f0f53 Mon Sep 17 00:00:00 2001 From: unknown <1326cy@gmail.com> Date: Wed, 26 Aug 2026 23:49:23 +0900 Subject: [PATCH] day29 --- .../3940. Limit Occurrences in Sorted Array.py" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "leetcode3/\353\202\250\355\232\250\354\240\225/3940. Limit Occurrences in Sorted Array.py" 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