Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 20, 2014 03:11
Show Gist options
  • Save Cee/6b30c42dbe7f505511b7 to your computer and use it in GitHub Desktop.
Save Cee/6b30c42dbe7f505511b7 to your computer and use it in GitHub Desktop.
public class Solution {
public void merge(int A[], int m, int B[], int n) {
int i = 0;
int j = 0;
while ((i < m) && (j < n)){
if (B[j] <= A[i]){
for (int k = m - 1; k >= i; k--)
A[k + 1] = A[k];
A[i] = B[j];
m++;
j++;
} else {
i++;
}
}
while (j < n){
A[i] = B[j];
i++;
j++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment