public class Solution {
public void merge(int A[], int m, int B[], int n) {
// Start typing your Java solution below
// DO NOT write main() function
if(A==null||B==null||A.length<m||B.length<n){
return;
}
if(n==0){
return;
}
int i=m+n-1;
int index_a=m-1;
int index_b=n-1;
for(;i>=0&&index_a!=-1&&index_b!=-1;i--){
if(A[index_a]>B[index_b]){
A[i]=A[index_a--];
}else{
A[i]=B[index_b--];
}
}
while(index_b!=-1){
A[i--]=B[index_b--];
}
}
}
Merge Sorted Array
最新推荐文章于 2022-06-26 11:00:52 发布