题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
#
#
# @param A int整型一维数组
# @param B int整型一维数组
# @return void
#
class Solution:
def qSort(self, arr, l, r):
if l >= r: return
i, j = l, r
while i < j:
while i < j and arr[j] >= arr[l]: j -= 1
while i < j and arr[i] < arr[l]: i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[l], arr[i] = arr[i], arr[l]
self.qSort(arr, l, i-1)
self.qSort(arr, i+1, r)
def merge(self , A, m, B, n):
# write code here
for i in range(m, m+n):
A[i] = B[i-m]
self.qSort(A, 0, m+n-1)
return A