1. 程式人生 > >leetcode python 033 旋轉數組查找

leetcode python 033 旋轉數組查找

假設 print port rand str stop else imp 升序

## 假設升序,
import random

def find(y):
l,m=len(y),0
while l>1:
n=int(l/2)
if y[0]<y[n]:
y=y[n:]
else:
y=y[:n]
m+=l-n
l=len(y)
return m

stop=1000
x=[x for x in range(0,stop)]
ans=random.randrange(0,stop)
print(‘answer is %s‘%str(ans))
y=x[ans:]+x[0:ans]
print(find(y))

leetcode python 033 旋轉數組查找