Could you please tell me where is my fault?


  • 0
    W

    when i test, nums1=[1,3,5,0,0,0],nums2=[2,4,6],m=3,n=3, it returns [2, 4, 5, 6, 0, 0]....SO CONFUSED. TAT

        nums=nums1
        i,j,k=0,0,0
        while i<m and j<n:
            if nums[i]<=nums2[j]:
                nums1[k]=nums[i]
                i+=1
            if nums[i]>nums2[j]:
                nums1[k]=nums2[j]
                j+=1
            k+=1
        while i<m:
            nums1[k]=nums[i]
            i+=1
            k+=1
        while j<n:
            nums1[k]=nums2[j]
            j+=1
            k+=1
        return nums1

Log in to reply
 

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