# 88. Merge Sorted Array ###### tags: `陣列` https://leetcode.com/problems/merge-sorted-array/ # 思路 1. 有些題目不用想太複雜,使用merge sort 等等。觀察一下,就可以用一般解去解。 2. index 的limitaion 很重要 ```python= 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. """ # limit the accessible index a,b,index=m-1,n-1,m+n-1 while b>=0: if a >=0 and nums1[a]>nums2[b]: # the nums1 array has all length of array nums1[index]=nums1[a] a-=1 else: nums1[index]=nums2[b] b-=1 index-=1 ```