剑指offer python版 数值的整数次方

def aa(base,exponent):
    if base==0 and exponent<=0:
        return False
    ret=bb(base,abs(exponent))
    if exponent<0:
        return 1/ret
    else:
        return ret
    
    
def bb(base,exponent):
    if exponent==0:
        return 1
    if exponent==1:
        return base
    
    
    ret=bb(base,exponent>>1)
    ret *=ret
    if exponent &1==1:
        ret *=base
    return ret

print(aa(3,5))

 

posted @ 2018-10-25 13:59  findtruth123  阅读(302)  评论(0编辑  收藏  举报