Is it a testing case mistake?


  • 0
    L

    There has a test case like this:

    [0]
    0
    [1]
    1
    

    Should it be:

    [0]
    1
    [1]
    1
    

    This is the code I submitted:

    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.
            """
            temp = []
            i = 0
            j = 0
            while i < len(nums1) and j < len(nums2):
                if nums1[i] <= nums2[j]:
                    temp.append(nums1[i])
                    i += 1
                else:
                    temp.append(nums2[j])
                    j += 1
            
            while i < len(nums1):
                temp.append(nums1[i])
                i += 1
                
            while j < len(nums2):
                temp.append(nums2[j])
                j += 1
                
            for i in range(0, m + n):
                nums1[i] = temp[i]
    

Log in to reply
 

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