Advertisement
serega1112

88

Dec 13th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. class Solution:
  2.     def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
  3.         """
  4.        Do not return anything, modify nums1 in-place instead.
  5.        """
  6.         p1 = m - 1
  7.         p2 = n - 1
  8.         p3 = len(nums1) - 1
  9.        
  10.         while p1 >= 0 or p2 >= 0:
  11.             if p1 < 0:
  12.                 nums1[p3] = nums2[p2]
  13.                 p2 -= 1
  14.             elif p2 < 0:                
  15.                 nums1[p3] = nums1[p1]
  16.                 p1 -= 1
  17.             elif nums1[p1] > nums2[p2]:
  18.                 nums1[p3] = nums1[p1]
  19.                 p1 -= 1
  20.             else:
  21.                 nums1[p3] = nums2[p2]
  22.                 p2 -= 1
  23.             p3 -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement