heap
Key Points
Thinking Patterns
An Example
Problems
Problems - Binary Heap Problem
Key Points
- Use array to present the
Binary Heap
. (完全二叉树)
Problems
Problems | Possible Solutions | Key Points | Code | Comments |
---|---|---|---|---|
215. Kth Largest Element in an Array | 1. Heap 2. Quick Sort 3. Quick Select |
heap | - |
295. Get the median of an ordered stream
Key Point
- Keep a max heap and min heap
May use the go built-in heap package
- The
up
anddown
operation is a typicalswim
andsink
operation of a heap
- The
Principle
- Using the heap sort. (if the stream is ordered, no need to order again)