博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
剑指Offer 16 数值的整数次方
阅读量:6949 次
发布时间:2019-06-27

本文共 703 字,大约阅读时间需要 2 分钟。

给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。

1 # -*- coding:utf-8 -*- 2 class Solution: 3     def Power(self, base, exponent): 4         if exponent == 0: 5             return 1 6         if exponent == 1: 7             return base 8         op = False 9         if exponent < 0:10             op = True11             exponent = -exponent12         result = 113         if exponent % 2 == 0:14             result = self.Power(base * base,exponent // 2)15         else:16             result = self.Power(base * base,exponent // 2) * base17         if op:18             result = 1 / result19         return result20         # write code here

 

转载于:https://www.cnblogs.com/asenyang/p/11013104.html

你可能感兴趣的文章
Windows下安装MongoDB
查看>>
virtualbox不能安装64位系统的解决方法
查看>>
选型 - QA testing tools 2/26/2016
查看>>
Linux培训大纲
查看>>
sqlalchemy(一)基本操作
查看>>
Python: pip常见的使用方法
查看>>
CSS 专业技巧收集
查看>>
centos7 链接网络
查看>>
myblog test
查看>>
ReentrantLock 实现原理
查看>>
初识Ansible
查看>>
监控mysql从服务器状态
查看>>
迭代模式
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
浅谈linux启动流程
查看>>
java/strust2实现多文件上传
查看>>
一个urllib的post方法的使用例子
查看>>
Python学习笔记(4)--- Flask开发入门
查看>>
C语言探索之旅】第一部分第四课第三章:变量的世界之显示变量内容
查看>>