Merge K Sorted Arrays
Last updated
Was this helpful?
Last updated
Was this helpful?
Given _k _sorted integer arrays, merge them into one sorted array.
Example
Given 3 sorted arrays:
return
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
.Do it in O(N log k).
_N _is the total number of integers.
_k _is the number of arrays.
K 路合并。可以用 heap,或者两两合并。用heap的方法: