Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions leetcode3/남효정/3940. Limit Occurrences in Sorted Array.py
Original file line number Diff line number Diff line change
@@ -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