堆类题目堆相关知识点
golang 最小堆实现
https://leetcode-cn.com/problems/kth-largest-element-in-a-stream/submissions/
参考 https://ieevee.com/tech/2018/01/29/go-heap.html#2-containerheap%E6%8F%90%E4%BE%9B%E7%9A%84%E6%96%B9%E6%B3%95
container/heap
4.1 heap.Init
4.2 heap.Push
4.3 heap.Pop
4.4 heap.Fix
4.5 heap.Remove
实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| type KthLargest struct { sort.IntSlice }
func (kl *KthLargest) Push(v interface{}) { kl.IntSlice = append(kl.IntSlice, v.(int)) }
func (kl *KthLargest) Pop() interface{} { a := kl.IntSlice v := a[len(a)-1] kl.IntSlice = a[:len(a)-1] return v }
|