非递归的快速幂/位运算


class Solution:
    def Power(self , base: float, exponent: int) -> float:
        if exponent<0:  # 如果幂小于0
            exponent = - exponent
            base = 1/base
        
        in_x = base
        res = 1
        
        while exponent!=0: 
            if exponent&1:    
                res = res*in_x
            in_x = in_x*in_x  # 幂运算
            exponent=exponent>>1  #向右移位
        return res