Java solution (0 ms)


  • 0
    A
        public void merge(int[] nums1, int m, int[] nums2, int n) {
            for (int i = n-- + m-- - 1; i >= 0; i--) {
                if (m < 0) {
                    nums1[i] = nums2[n--];
                } else if (n < 0) {
                    nums1[i] = nums1[m--];
                } else if (nums1[m] > nums2[n]) {
                    nums1[i] = nums1[m--];
                } else {
                    nums1[i] = nums2[n--];
                }
            }
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.