C# (Sharp) solution, two pointers, beat 88%, easy to understand


  • 0
                int i = m - 1, j = n - 1;
                while (j >= 0)
                {
                    if (i < 0) { nums1[j] = nums2[j--]; }
                    else
                    {
                        if (nums1[i] > nums2[j])
                        {
                            nums1[i + j + 1] = nums1[i--];
                        }
                        else
                        {
                            nums1[i + j + 1] = nums2[j--];
                        }
                    }
                }
    

Log in to reply
 

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