Skip to content

Commit da6380b

Browse files
committed
Time: 50 ms (55.36%), Space: 16.6 MB (37.68%) - LeetHub
1 parent 1007574 commit da6380b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# time complexity: O(nlogn)
2+
# space complexity: O(n)
3+
from typing import Counter, List
4+
5+
6+
class Solution:
7+
def frequencySort(self, nums: List[int]) -> List[int]:
8+
freq = Counter(nums)
9+
return sorted(nums, key=lambda x: (freq[x], -x))
10+
11+
12+
nums = [1, 1, 2, 2, 2, 3]
13+
print(Solution().frequencySort(nums))

0 commit comments

Comments
 (0)