zoukankan      html  css  js  c++  java
  • 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))

    ----蚂蚁不在线
  • 相关阅读:
    敌兵布阵
    Points on Cycle
    Hero
    E~最少拦截系统
    C
    A
    J
    H
    G
    A
  • 原文地址:https://www.cnblogs.com/offline-ant/p/9462901.html
Copyright © 2011-2022 走看看