python 88. Merge Sorted Array.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 88. Merge Sorted Array.py相关的知识,希望对你有一定的参考价值。

# Time: O(n)
# Space: O(n)
# 88. Merge Sorted Array
'''
num1 = [1,3,5,7] 
num2 = [2,4,6]

'''

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.
        """
        while m > 0 and n > 0:
            if nums1[m-1] >= nums2[n-1]:
                nums1[m+n-1] = nums1[m-1]
                m -= 1
            else:
                nums1[m+n-1] = nums2[n-1]
                n -= 1
        if n > 0:
            nums1[:n] = nums2[:n]

以上是关于python 88. Merge Sorted Array.py的主要内容,如果未能解决你的问题,请参考以下文章

88. Merge Sorted Array [easy] (Python)

88. Merge Sorted Array

Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]

LeetCode 88 Merge Sorted Array(合并排序数组)(*)

Leetcode-88. Merge Sorted Array

#Leetcode# 88. Merge Sorted Array