LintCode 6.合并排序数组 II
2018-01-25 00:14
351 查看
LintCode 6.合并排序数组 II
问题描述
合并两个排序的整数数组A和B变成一个新的数组。样例给出 A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6]
问题分析
将A,B两个数组整合到一起,排序。代码
class Solution { public: /* * @param A: sorted integer array A * @param B: sorted integer array B * @return: A new sorted integer array */ vector<int> mergeSortedArray(vector<int> &A, vector<int> &B) { // write your code here for(int i = 0; i < B.size(); i++) { A.push_back(B[i]); } sort(A.begin(), A.end()); return A; } };
代码思路
将数组B中的元素逐个添加到A数组的尾部,sort函数对A数组中从开始到末尾的元素进行排序。相关文章推荐
- LintCode Merge Sorted ArrayII 合并排序数组 II
- lintcode之 合并排序数组 II
- LintCode Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
- Lintcode:合并排序数组
- LintCode_63_搜索旋转排序数组 II
- LintCode:搜索旋转排序数组 II
- LintCode Python 101. 删除排序数组中的重复数字 II
- lintcode 中等题:search in rotated sorted arrayII 搜索旋转排序数组II
- LintCode之6 合并排序数组
- 合并排序数组 II
- lintcode 165. 合并两个排序链表
- lintcode-39-恢复旋转排序数组
- LintCode-合并排序数组 II
- lintcode -- 最大子数组II
- lintcode-64-合并排序数组 II
- lintcode-删除排序链表中的重复数字 II
- LintCode : 寻找旋转排序数组中的最小值
- Lintcode:恢复旋转排序数组
- lintcode——把排序数组转换为高度最小的二叉搜索树
- lintcode:两数组的交 II