LeetCode刷题(15)

来源:互联网 发布:javascript 取消 bind 编辑:程序博客网 时间:2024/06/12 20:46

Pow(x,n)
so easy, 无甚可说

class Solution(object):    def myPow(self, x, n):        """        :type x: float        :type n: int        :rtype: float        """        res = 1        count = abs(n)        while count > 0:            if count % 2 == 1:                res = res * x            count = count / 2            x = x * x        if n >= 0 :            return res        else :            return 1/res