Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Good one. My first reaction to this problem is the same idea as this answer: https://leetcode.com/discuss/37365/accepted-c-solution-o-nlogn-using-maxheap

So basically we need a MaxHeap which supports add\remove\top operations. But in C++ priority_queue doesn't support removal of arbitary elements. You may think that your own heap is needed to code, but in the above link, some book-keeping work can be a workaround: we simply record which elements are removed, and we simply pop it out when necessary.

And another solution is "Divide and Conqure": https://leetcode.com/discuss/37444/my-220ms-divide-and-conquer-solution-in-python-o-nlogn

posted on 2015-05-29 01:44  Tonix  阅读(390)  评论(0编辑  收藏  举报