I keep failing the case for nums1 = , m = 0, nums2 = , n = 1. Solution should be . I even tried to print out the list at the end and it is . However, OJ keeps thinking the output is .
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. """ nums1 = nums1[:m] nums2 = nums2[:n] one = 0 #the index of the next element we want to examine in nums1 two = 0 #the index of the next element we want to examine in nums2 total = 0 #the index of the next comparison between num1 and num2 while one < m and two < n and total < m + n: if nums1[one] <= nums2[two]: one += 1 else: nums1.insert(total, nums2[two]) one += 1 #don't forget this because you insert one element, so you shift everything by 1 two += 1 total += 1 if two <= n: nums1[total:] = nums2[two:n]