Given two ordered integer arrays nums1 and nums2, merge nums2 into nums1 such that num1 becomes an ordered array.

Description:

Initialize nums1 and nums2 to m and n, respectively. You can assume that NUMs1 has enough space (space size greater than or equal to m + n) to hold elements in NUMs2.

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.
        """
        for i in range(len(nums1)):
            if nums1[i] == 0:
                try:
                    nums1[i] = nums2.pop(0)
                except:
                    pass

        print nums1.sort()
Copy the code