[leetcode刷题系列]Merge Sorted Array
2013-08-07 12:23
351 查看
- - 我还是想了一会的。。虽然简单。
class Solution { public: void merge(int A[], int m, int B[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function // at first, move element of a back for(int i = m - 1; i >= 0; -- i) A[i + n] = A[i]; int pa = n, pa_end = m + n; int pb = 0, pb_end = n; int valid = 0; for(; pa < pa_end && pb < pb_end;){ if(A[pa] < B[pb]) A[valid ++ ] = A[pa ++ ]; else A[valid ++ ] = B[pb ++ ]; } while(pa < pa_end) A[valid ++ ] = A[pa ++ ]; while(pb < pb_end) A[valid ++ ] = B[pb ++ ]; } };
相关文章推荐
- Merge Sorted Array leetcode
- [leetcode] Merge Sorted Array
- Leetcode解题笔记-Merge sorted Array
- LeetCode Merge Sorted Array
- 【Leetcode长征系列】Merge Sorted Array
- [LeetCode] Merge Sorted Array [22]
- [LeetCode]Merge Sorted Array
- LeetCode Merge Sorted Array 88
- LeetCode : Merge Sorted Array
- [leetcode]Merge Sorted Array
- [leetcode]Merge Sorted Array
- [leetcode][array][two pointers] Merge Sorted Array
- LeetCode Merge Sorted Array
- 【LEETCODE】88-Merge Sorted Array
- [Leetcode] Merge Sorted Array (Java)
- leetcode---merge-sorted-array---数组
- Leetcode 88 Merge Sorted Array
- LeetCode[Array]: Merge Sorted Array
- Merge Sorted Array —— Leetcode
- LeetCode:Merge Sorted Array