Buttercola: LinkedIn: Merge K sorted Iterators
LinkedIn: Merge K sorted Iterators
interface是这个 Iterable<Integer> mergeKSortedIterators(Iterators[] iters)
也就是给每个array的iterator,然后merge.
Solution:
The problem looks straight-forward: just to a minHeap and continuously poll and add elements into the heap.
The only pitfall for this problem is the input is Iterators. When we compare values in the heap, if we use next(), we might lose the next() value. Thus we need to defined a customized class to store the value.
也就是给每个array的iterator,然后merge.
Solution:
The problem looks straight-forward: just to a minHeap and continuously poll and add elements into the heap.
The only pitfall for this problem is the input is Iterators. When we compare values in the heap, if we use next(), we might lose the next() value. Thus we need to defined a customized class to store the value.
Read full article from Buttercola: LinkedIn: Merge K sorted Iterators
No comments:
Post a Comment