Merge Sorted Array LeetCode solution in Python
1class Solution(object):2def merge(self, nums1, m, nums2, n):3# Initialize nums1's index4i = m - 15# Initialize nums2's index6j = n - 17# Initialize a variable k to store the last index of the 1st array...8k = m + n - 19while j >= 0:10if i >= 0 and nums1[i] > nums2[j]:11nums1[k] = nums1[i]12k -= 113i -= 114else:15nums1[k] = nums2[j]16k -= 117j -= 1