Solution to "Sort Array by Increasing Frequency" on Leetcode
1class Solution:
2 def frequencySort(self, nums: List[int]) -> List[int]:
3 freqs = collections.Counter()
4 for num in nums:
5 freqs[num*-1] += 1
6
7 sorted_freq = sorted(freqs.items(), key = lambda x: (x[1],x[0]))
8 res = []
9 for key,value in sorted_freq:
10 for i in range(value):
11 res.append(key * -1)
12 return res
Solution to "Count Number of Texts" question on Leetcode.
Solution to "Second Minimum Node In a Binary Tree" on Leetcode.