class Solution:
#参数A:有序整数数组A
#参数B:有序整数数组B
#返回:一个新的有序整数数组
def merge(self, A, B):
i,j = 0,0
c=[]
while i<len(A) and j<len(B):
if A[i]<B[j]:
c.append(A[i])
i+=1
else:
c.append(B[j])
j+=1
while i < len(A):
c.append(A[i])
i+=1
while j < len(B):
c.append(B[j])
j += 1
return c
if name == ‘main’:
A=[1,2,3]
B=[1,4,5,6]
solution = Solution()
print(“输入:”,A," ",B)
print(“输出:”, solution.merge(A,B))