蚂蚁不在线

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))

posted on 2018-08-12 14:12  蚂蚁不在线  阅读(375)  评论(0编辑  收藏  举报

导航