美文网首页
486. Merge K Sorted Arrays

486. Merge K Sorted Arrays

作者: 鸭蛋蛋_8441 | 来源:发表于2019-07-27 06:14 被阅读0次

Description

Given k sorted integer arrays, merge them into one sorted array.

Example

Example 1:

Input:

  [

    [1, 3, 5, 7],

    [2, 4, 6],

    [0, 8, 9, 10, 11]

  ]

Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Example 2:

Input:

  [

    [1,2,3],

    [1,2]

  ]

Output: [1,1,2,2,3]

Challenge

Do it in O(N log k).

N is the total number of integers.

k is the number of arrays.

思路:

1.分治法两两归并

2.用堆

基本思路和577的完全一样,只不过577合并区间的方法稍微复杂一点。

代码:

相关文章

网友评论

      本文标题:486. Merge K Sorted Arrays

      本文链接:https://www.haomeiwen.com/subject/ivqsrctx.html