1636. Sort Array by Increasing Frequency
## 思路
用Counter計算num出現次數, 再用(cnt, -num) 做排序
## Complexity
Time: O(N logN)
Space: O(N)
## Code
Counter + Heap
```python
class Solution:
def frequencySort(self, nums: List[int]) -> List[int]:
counter = Counter(nums)
arr = [(cnt, -num) for num, cnt in counter.items()]
heapq.heapify(arr)
ans = []
while arr:
cnt, num = heapq.heappop(arr)
ans += [-num] * cnt
return ans
```
Counter + Sorted
```python
class Solution:
def frequencySort(self, nums: List[int]) -> List[int]:
counter = Counter(nums)
return sorted(nums, key=lambda x: (counter[x], -x))
```