Skip to content

Instantly share code, notes, and snippets.

@amraks
Created February 17, 2019 18:39
Show Gist options
  • Save amraks/8e74614f64caa5c0aded42febfb43813 to your computer and use it in GitHub Desktop.
Save amraks/8e74614f64caa5c0aded42febfb43813 to your computer and use it in GitHub Desktop.
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.
"""
r = len(nums1) - 1
i = m - 1
j = len(nums2) - 1
while i >= 0 and j >= 0:
if nums1[i] >= nums2[j]:
nums1[r] = nums1[i]
i -= 1
r -= 1
else:
nums1[r] = nums2[j]
j -= 1
r -= 1
while j >= 0:
nums1[r] = nums2[j]
r -= 1
j -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment