码迷,mamicode.com
首页 > 编程语言 > 详细

[LintCode] 合并排序数组II

时间:2015-06-29 23:48:23      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:

 1 class Solution {
 2 public:
 3     /**
 4      * @param A: sorted integer array A which has m elements, 
 5      *           but size of A is m+n
 6      * @param B: sorted integer array B which has n elements
 7      * @return: void
 8      */
 9     void mergeSortedArray(int A[], int m, int B[], int n) {
10         // write your code here
11         int pa = m - 1, pb = n - 1, p = m + n - 1;
12         while (pa >= 0 && pb >= 0) {
13             if (A[pa] >= B[pb]) A[p--] = A[pa--];
14             else A[p--] = B[pb--];
15         }
16         while (pb >= 0) A[p--] = B[pb--];
17     }
18 };

 

[LintCode] 合并排序数组II

标签:

原文地址:http://www.cnblogs.com/jcliBlogger/p/4609088.html

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