Lintcode6 Merge Two Sorted Arrays solution 题解

【题目描述】

Merge two given sorted integer array A and B into a new sorted integer array.

合并两个排序的整数数组A和B变成一个新的数组。

【题目链接】

http://www.lintcode.com/en/problem/merge-two-sorted-arrays/

【题目解析】

A和B都已经是排好序的数组,我们只需要从后往前比较就可以了。

因为A有足够的空间容纳A + B,我们使用游标i指向m + n - 1,也就是最大数值存放的地方,从后往前遍历A,B,谁大就放到i这里,同时递减i。

【题目答案】

http://www.jiuzhang.com/solutions/merge-sorted-array/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章