This commit is contained in:
parent
1e0eafc883
commit
00995bb067
1 changed files with 8 additions and 0 deletions
8
easy/sort_array_by_increasing_frequency.py
Normal file
8
easy/sort_array_by_increasing_frequency.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
# https://leetcode.com/problems/sort-array-by-increasing-frequency
|
||||||
|
from collections import Counter
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def frequencySort(self, nums: List[int]) -> List[int]:
|
||||||
|
freq = Counter(nums)
|
||||||
|
return sorted(nums, key=lambda x: (freq[x], -x))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue