stacks:
https://leetcode.com/problems/decode-string/
https://leetcode.com/problems/binary-search-tree-iterator/
第k大问题以及前k大问题
clearance:
- The kth or top k?
- What if there are duplicates? How to define the kth?
- How large is N and k?
第k大:
方法:
4. quicksort. O(nlng) time + O(1) space, 但是收到内存的影响,有可能不能把所有的数据都放入内存中排序
5. quick select, O(n) time + O(1) space, 平均时间为n,最差时间为1, 也受到内存的影响,需要读入所有数据
6. min heap, O(nlgk) time + O(k) space, 如果数据从文件读入而k不是很大,比较合适
7. max heap, O(klgn + n) time + O(n) space,
8. 使用hash表,从大到小统计K个元素即可,时间复杂度为0(N),但提高了空间复杂度。
https://www.raychase.net/4450