Python解法:
def relativeSortArray(arr1, arr2): arr = [0 for _ in range(110)] new = [] for a in range(len(arr1)): arr[arr1[a]] += 1 for b in range(len(arr2)): while arr[arr2[b]] > 0: new.append(arr2[b]) arr[arr2[b]] -= 1 for c in range(len(arr)): while arr[c] > 0: new.append(c) arr[c] -= 1 return new print(relativeSortArray([2,3,1,3,2,4,6,7,9,2,19], [2,1,4,3,9,6]))
res = [] for i in arr2: while i in arr1: res.append(i) arr1.remove(i) return res + sorted(arr1)