Topic
Given sorted integer arrays A and B, merge B into a as one sorted array.
Note:
You could assume that A have enough space (size that's greater or equal to m + n) to the hold additional Eleme NTS from B. The number of elements initialized in A and B is m and nrespectively.
PS: The following solution is very ingenious, I did not think, is to learn from the leet inside a great god code.
Code
public class Solution {public void merge (int a[], int m, int. b[], int n) {while (M > 0 && n > 0) { if (a[m-1] > B[n-1]) { a[m+n-1] = a[m-1]; m--; } else { a[m+n-1] = b[n-1]; n--; } } while (n > 0) { a[n-1] = b[n-1]; n--;}}}
code Download: Https://github.com/jimenbian/GarvinLeetCode
/********************************
* This article from the blog "Bo Li Garvin"
* Reprint Please indicate the source : Http://blog.csdn.net/buptgshengod
******************************************/
"Leetcode from zero single row" No88.merge Sorted Array