* Merge two ordered arrays
Train of thought 1 : Sort after merge , time O((m+n)log(m+n))
Train of thought 2 : Double pointer class Solution: def merge(self, nums1: List[int], m: int, nums2: List[
int], n: int) -> None: """ Do not return anything, modify nums1 in-place
instead. """ p1 = m - 1 p2 = n - 1 p3 = m + n - 1 while p1 >= 0 and p2 >= 0: if
nums1[p1] < nums2[p2]: nums1[p3] = nums2[p2] p2 -= 1 else: nums1[p3] = nums1[p1]
p1-= 1 p3 -= 1 nums1[0:(p2+1)] = nums2[0:(p2+1)] return nums1 # 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[:] =
sorted(nums1[:m] + nums2)

Technology
©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )