88. Merge Sorted Array*

原创 2016年08月29日 21:03:52

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

Note:
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.

My 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.
        """
        if n ==0:
            return 
        if m == 0:
            nums1.extend(nums2)
            return 
        p1 = 0
        p2 = 0
        while p2<n and p1<m+n:
            if nums2[p2]<=nums1[p1]:
                nums1.insert(p1,nums2[p2])
                p2+=1
            p1+=1
        nums1.extend(nums2[p2:])
            


版权声明:本文为博主原创文章,未经博主允许不得转载。

27. Remove Element \ 66. Plus One \ 88. Merge Sorted Array

27. Remove Element法一:class Solution { public: int removeElement(vector& nums, int val) { ...

(数组)leetcode 88:Merge Sorted Array

(数组)leetcode 88:Merge Sorted Array

LeetCode 88. Merge Sorted Array 归并的过程

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. 题意:对于...

[LeetCode]--88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: Y...

[leetcode]88. Merge Sorted Array (java)

题目描述: Merge two sorted linked lists and return it as a new list. The new list should be made by sp...

Leetcode 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: Y...

88. Merge Sorted Array

这道题目很简单,但是意思要看懂,给的参数和条件。 描述: Given two sorted integer arrays nums1 and nums2, merge nums2 into num...

LeetCode 88 — Merge Sorted Array(C++ Java Python)

题目:http://oj.leetcode.com/problems/merge-sorted-array/ Given two sorted integer arrays A and B, mer...

leetcode88---Merge Sorted Array(合并有序数组)

问题描述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Not...
  • will130
  • will130
  • 2016年01月14日 18:03
  • 228

[LeetCode]88.Merge Sorted Array

【题目】 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may a...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:88. Merge Sorted Array*
举报原因:
原因补充:

(最多只允许输入30个字)