[LintCode笔记了解一下]64.合并排序数组
生活随笔
收集整理的這篇文章主要介紹了
[LintCode笔记了解一下]64.合并排序数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Given two sorted integer arrays A and B, merge B into A as one sorted array.
思路:
因為A的后面的部分都是空的留出來給我們放元素,所以最好是從后往前塞元素進去
void mergeSortedArray(int A[], int m, int B[], int n) {// write your code hereint i = m-1;int j = n-1;int index = m+n-1;while(i>=0&&j>=0){if(A[i]>=B[j]){A[index]=A[i];index--;i--;}else{A[index]=B[j];index--;j--;}}while(i>=0){A[index--]=A[i--];}while(j>=0){A[index--]=B[j--];}}?
轉載于:https://www.cnblogs.com/otakuhan/p/8606869.html
總結
以上是生活随笔為你收集整理的[LintCode笔记了解一下]64.合并排序数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大容量U盘选择哪种系统文件格式比较好
- 下一篇: NYOJ90 整数划分(经典递归和dp)