C# code


  • 0
    P
    public void Merge(int[] nums1, int m, int[] nums2, int n) {
                int x = m + n - 1;
                for (int i = m-1;i>=0;i--)
                    nums1[x--] = nums1[i];
                int a = n, b = 0, c = 0;
                while (a < m + n && b < n)
                {
                    if (nums1[a] < nums2[b])
                        nums1[c++] = nums1[a++];
                    else
                        nums1[c++] = nums2[b++];
                }
                while (a < m + n)
                    nums1[c++] = nums1[a++];
                while (b < n)
                    nums1[c++] = nums2[b++];
        }
    

Log in to reply
 

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