'''
Created on 2015年11月10日
@author: SphinxW
'''
# 合并排序數(shù)組
#
# 合并兩個排序的整數(shù)數(shù)組A和B變成一個新的數(shù)組贡翘。
# 樣例
#
# 給出A=[1,2,3,4]雪隧,B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6]
# 挑戰(zhàn)
#
# 你能否優(yōu)化你的算法,如果其中一個數(shù)組很大而另一個數(shù)組很性儆蟆?
class Solution:
#@param A and B: sorted integer array A and B.
#@return: A new sorted integer array
def mergeSortedArray(self, A, B):
# write your code here
res = []
while len(A) > 0 and len(B) > 0:
thisA = A[0]
thisB = B[0]
if thisA < thisB:
res.append(thisA)
del A[0]
else:
res.append(thisB)
del B[0]
if len(A) == 0:
res += B
if len(B) == 0:
res += A
return res