美文网首页
64. Merge Sorted Array

64. Merge Sorted Array

作者: 鸭蛋蛋_8441 | 来源:发表于2019-07-26 05:09 被阅读0次

Description

Given two sorted integer arrays A and B, merge B into A as one sorted array.

You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.

Example

Example 1:

Input:[1, 2, 3] 3  [4,5]  2

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

Explanation:

After merge, A will be filled as [1, 2, 3, 4, 5]

Example 2:

Input:[1,2,5] 3 [3,4] 2

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

Explanation:

After merge, A will be filled as [1, 2, 3, 4, 5]

思路:

双指针, 从list的最后一位开始, 用Index存每次要更新的位置。

代码:

相关文章

网友评论

      本文标题:64. Merge Sorted Array

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