p1
to m - 1
, p2
to n - 1
, and p
to m + n - 1
.p2
>= 0:
a. If p1
>= 0 and nums1[p1]
> nums2[p2]
, place nums1[p1]
at nums1[p]
, decrement p1
and p
.
b. Otherwise, place nums2[p2]
at nums1[p]
, decrement p2
and p
.nums2
that haven't been copied (when p1
< 0), copy the remaining elements of nums2
to the beginning of nums1
.