-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ88
More file actions
38 lines (37 loc) · 1.08 KB
/
Q88
File metadata and controls
38 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution:
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: void Do not return anything, modify nums1 in-place instead.
"""
if n==0:
nums1=nums1
elif m==0:
nums1[0:n]=nums2[0:n]
else:
j=0
for i in range(m+n):
if j!=n:
if nums1[i]>nums2[j]:
for k in range(1,m+n-i):
nums1[m+n-k]=nums1[m+n-k-1]
nums1[i]=nums2[j]
j+=1
else:
break
for k in range(n-j):
nums1[m+j+k]=nums2[j+k]
class Solution: #solution
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: void Do not return anything, modify nums1 in-place instead.
"""
nums1[m:] = nums2[:n]
nums1.sort()