题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
def merge(self , A, m, B, n):
# write code here
#先复制到A数组尾部,再来一个插入排序就行;
for i in range(n):
A[i+m]=B[i]
i=m
while i<m+n:
while i<m+n and A[i]>=A[i-1]:
i+=1
if i==m+n:break
temp=A[i]
j=i-1
while j>=0 and A[j]>temp:
A[j+1]=A[j]
j-=1
A[j+1]=temp
i+=1