[CareerCup] 11.1 Merge Arrays 合并数组
生活随笔
收集整理的这篇文章主要介绍了
[CareerCup] 11.1 Merge Arrays 合并数组
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
11.1 You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted orde.
LeetCode上的原题,请参见我之前的博客Merge Sorted Array 混合插入有序数组。
class Solution { public:void merge(vector<int> &a, int m, vector<int> &b, int n) {int cnt = m + n - 1;--m; --n;while (m >= 0 && n >= 0) a[cnt--] = a[m] > b[n] ? a[m--] : b[n--];while (n >= 0) a[cnt--] = b[n--];} };本文转自博客园Grandyang的博客,原文链接:合并数组[CareerCup] 11.1 Merge Arrays ,如需转载请自行联系原博主。
总结
以上是生活随笔为你收集整理的[CareerCup] 11.1 Merge Arrays 合并数组的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: CSS补漏
- 下一篇: swift中使用core data