1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class Solution {
public void merge(int[] nums1, int m, int[] nums2, int n) {
int end1 = m - 1, end2 = n - 1, end = m + n - 1;
while (end1 >= 0 && end2 >= 0) {
if (nums2[end2] > nums1[end1]) {
System.out.println("nums2 " + end2);
nums1[end--] = nums2[end2--];
} else {
System.out.println("nums1 " + end1);
nums1[end--] = nums1[end1--];
}
}
// no need to check nums1 since it's already there and in order
while (end2 >= 0) {
nums1[end--] = nums2[end2--];
}
}
}