码迷,mamicode.com
首页 > 其他好文 > 详细

Lintcode6 Merge Two Sorted Arrays solution 题解

时间:2017-04-16 10:12:51      阅读:137      评论:0      收藏:0      [点我收藏+]

标签: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/


Lintcode6 Merge Two Sorted Arrays solution 题解

标签:solution   空间   

原文地址:http://12799252.blog.51cto.com/12789252/1916350

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!