leetcode python 033 旋转数组查找

Posted 蚂蚁不在线

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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))





















以上是关于leetcode python 033 旋转数组查找的主要内容,如果未能解决你的问题,请参考以下文章