1636. Sort Array by Increasing Frequency

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1636

class Solution:
    def frequencySort(self, nums: List[int]) -> List[int]:
        cnt = Counter(nums)
        return sorted(nums, key=lambda x: (cnt[x], -x))