题目
Given a string, sort it in decreasing order based on the frequency of characters.
示例1:
1 | Input: |
示例2:
1 | Input: |
示例3:
1 | Input: |
提示:
- You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
- Your algorithm’s time complexity must be better than O(n log n), where n is the array’s size.
解法
解法一:
构造一个大顶堆,遍历取完即可。
JAVA
1 | class Node { |