leetcode python 033 旋转数组查找

## 假设升序,
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))

猜你喜欢

转载自www.cnblogs.com/offline-ant/p/9462901.html