Why I can use 'print' to output correct nums1, but in test case, my answer is wrong?


  • 0
    8

    Programming Language

    Python

    Input

    [0]
    0
    [1]
    1

    code

    class Solution(object):
        def merge(self, nums1, m, nums2, n):
            """
            :type nums1: List[int]
            :type m: int
            :type nums2: List[int]
            :type n: int
            :rtype: void Do not return anything, modify nums1 in-place instead.
            """
            i = j = 0
            
            while(1):
                if i >= m:
                    nums1 = nums1[:i]+nums2[j:]
                    break
                
                if j >= n:
                    break
                
                if nums1[i] > nums2[j]:
                    nums1.insert(i,nums2[j])
                    j+=1
                    i+=1
                else:
                    i+=1
            print nums1
    

    stdout

    [1]

    My Answer

    [0]

    Expected Answer

    [1]


Log in to reply
 

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