Created
February 17, 2019 18:39
-
-
Save amraks/8e74614f64caa5c0aded42febfb43813 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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