Skip to content

Commit dc797ef

Browse files
Update 088.py
1 parent 2e3bb0a commit dc797ef

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

001-500/088.py

+27
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,30 @@ def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
1818
k-=1
1919

2020

21+
22+
class Solution(object):
23+
def merge(self, nums1, m, nums2, n):
24+
"""
25+
:type nums1: List[int]
26+
:type m: int
27+
:type nums2: List[int]
28+
:type n: int
29+
:rtype: None Do not return anything, modify nums1 in-place instead.
30+
"""
31+
i = m+n-1
32+
j = n-1
33+
k = m-1
34+
35+
while j>=0 and k>=0:
36+
if nums2[j] > nums1[k]:
37+
nums1[i]=nums2[j]
38+
j-=1
39+
else:
40+
nums1[i]=nums1[k]
41+
k-=1
42+
i-=1
43+
44+
while i>=0 and j>=0:
45+
nums1[i]=nums2[j]
46+
j-=1
47+
i-=1

0 commit comments

Comments
 (0)