See the other Department of the pen Test, found that the topic: two sequential arrays of the merger, so try to write in Python
Specific as follows:
if __name__ == ' __main__ ': a=[2,4,6,8,9,10] b=[ 0,1,3,6,7,9,100,134] counta=countb=0# record where the two arrays were traversed c=[] for i in range (Counta,len (a)): for j in range (Countb,len (b)): print "B[j]:",j,b[j] if (B[j]<=a[i]): c.append (B[j]) countb=countb+1#append B[j], then the traversal of the B array should be self-increasing else: c.append (A[i]) &NBsp; counta=counta+1# Append A[i], then the record of the traversal of a array should be self-increasing Why would break# break? Because to this location, the B array can not continue to traverse down, the traversal of a #现在就需要吧两个数组中剩余的元素依次append到c中即可 if (Counta<len (a)): for i in range (CountA, Len (a)): c.append (A[i]) if (Countb<len (b)): for j in range (Countb,len (b)): c.append (b[ J]) print c
This article is from "H2O's Operation & Development Road" blog, reprint please contact the author!
Merge of two ordered arrays, Python version