1 Star 0 Fork 1

Raymond.Z / GeeKe-QinChao

forked from Yobs / algorithm-geeke-qc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-50-pow.py 470 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yobs 提交于 2021-01-02 20:46 . add lc-50-pow.py
# 极客时间 - 22 讲
# LeetCode 50 - 求 x 的 n 次方
# 1.暴力求解
# 2.分而治之
# 3.非递归算法
# 分治思想关键是将 n 递减的速度提上来,在 n 为偶数的时候,其时间复杂度是 O(logN)
# 分而治之
def myPow(x, n):
if not n:
return 1
if n < 0:
return 1 / myPow(x, -n)
if n % 2:
return x * myPow(x, n-1)
return myPow(x*x, n / 2)
print("Result = " + str(myPow(2, 4)))
# 非递归算法
Python
1
https://gitee.com/raymond_Z/gee-ke-qin-chao.git
git@gitee.com:raymond_Z/gee-ke-qin-chao.git
raymond_Z
gee-ke-qin-chao
GeeKe-QinChao
master

搜索帮助