Merge Sorted Array LeetCode solution in Python

1
class Solution(object):
2
def merge(self, nums1, m, nums2, n):
3
# Initialize nums1's index
4
i = m - 1
5
# Initialize nums2's index
6
j = n - 1
7
# Initialize a variable k to store the last index of the 1st array...
8
k = m + n - 1
9
while j >= 0:
10
if i >= 0 and nums1[i] > nums2[j]:
11
nums1[k] = nums1[i]
12
k -= 1
13
i -= 1
14
else:
15
nums1[k] = nums2[j]
16
k -= 1
17
j -= 1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0