9月6日小红书测开笔试
1、部分排序(过77%超时,为啥?)
def subSort(arr): if len(arr) < 2: return [-1,-1] lmax,rmin,l,r,n = arr[0],arr[-1],-1,-1,len(arr) for i in range(n): if arr[i] < lmax: r = i lmax = max(lmax,arr[i]) if arr[n-1-i] > rmin: l = n-1-i rmin = min(rmin,arr[n-1-i]) return [l,r] 2、找出不在数组中的最小自然数(100%)def findMin(arr): arr = [i for j in arr for i in j] hashmap = [0]*len(arr) for i in arr: if 0 < i <= len(arr): hashmap[i-1] = i for index in range(len(arr)): if hashmap[index] != index + 1: return index + 1 return len(arr)+1 3、(9%)