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.
- """
- p1 = m - 1
- p2 = n - 1
- p3 = len(nums1) - 1
- while p1 >= 0 or p2 >= 0:
- if p1 < 0:
- nums1[p3] = nums2[p2]
- p2 -= 1
- elif p2 < 0:
- nums1[p3] = nums1[p1]
- p1 -= 1
- elif nums1[p1] > nums2[p2]:
- nums1[p3] = nums1[p1]
- p1 -= 1
- else:
- nums1[p3] = nums2[p2]
- p2 -= 1
- p3 -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement