Simple C# Solution


  • 0
    B
    public void Merge(int[] nums1, int m, int[] nums2, int n) {
        if (m == 0 && n == 0)
            return;
        
        var i = m + n - 1;
        m -= 1;
        n -= 1;
        
        while(m >= 0 && n >= 0){
            if (nums1[m] >= nums2[n]){
                nums1[i--] = nums1[m--];
            }
            else{
                nums1[i--] = nums2[n--];
            }
        }
        
        while (n >= 0){
            nums1[i--] = nums2[n--];
        }
    }

Log in to reply
 

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