[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