
堆排序
qq_30339595
人类,诗意地栖息在大地上。
展开
-
查找前k个高频元素
思路一:库函数(一行)class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: return [item[0] for item in collections.Counter(nums).most_common(k)]思路二:堆class Solution:...转载 2019-12-19 15:09:46 · 183 阅读 · 0 评论 -
堆排序模板
const int maxn=100;int heap[maxn];int n;void downadjust(int low,int high){//下沉,其实为了是把下一层大的数浮上来。 int i=low,j=2*i; while(j<=high){ if(j+1<=high&&heap[j+1]>heap[j])swap(heap[j+1]...原创 2018-03-11 22:41:28 · 247 阅读 · 0 评论