Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- """
- first = m - 1
- second = n - 1
- third = m + n - 1
- while(first >= 0 and second >=0):
- if nums1[first] >= nums2[second]:
- nums1[third] = nums1[first]
- third -= 1
- first -= 1
- else:
- nums1[third] = nums2[second]
- third -= 1
- second -= 1
- while(second >= 0):
- nums1[third] = nums2[second]
- second -= 1
- # made the mistake of not decreasing the third pointer
- third -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement