Combine Two Non-Decreasing Arrays
Given two non-decreasing arrays nums1 and nums2 , combine them into a final array.
- Instead of returning the resulting array, modify the array nums1 .
- Array nums1 is of length m+n , where m is the length of actual values. The remaining n spots are placeholders for final result.
- Modify nums1 with the content of nums2 so that final non-decreasing array is stored in nums1 .
Solution
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: None Do not return anything, modify nums1 in-place instead.
"""
i,j = 0,0
# let us create an array for our result
nums1temp = nums1[:]
while True:
if i