java solution 0ms


  • 0
    public void merge(int[] nums1, int m, int[] nums2, int n) {
            int k = m + n -1;
            while(m >= 1 && n >= 1 )
                nums1[k--] = nums1[m-1]>=nums2[n-1 ] ? nums1[m-- -1] : nums2[n-- -1];
            while(n >= 1)
                nums1[k--] = nums2[n-- -1]; 
     }
    

  • 0
    C

    what does nums1[m-- -1] do?


  • 0

    you can understand like this :

    nums1[m-1];
    m--;
    

    everytime you get the element of nums1 or nums2 , the pointer must be taken one step back


Log in to reply
 

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