lintcode:Pow(x, n)
2016-03-16 19:03
260 查看
Pow(x, n)
Implement pow(x, n).解题
public class Solution { /** * @param x the base number * @param n the power number * @return the result */ public double myPow(double x, int n) { // Write your code here if(x == 0) return 0; if(n == 0) return 1.0; if( n<0) return 1.0/(myPow(x,-n)); double res = x; while(n>1){ res*=x; n--; } return res; } }
Java Code
class Solution: # @param {double} x the base number # @param {int} n the power number # @return {double} the result def myPow(self, x, n): # Write your code here return x**n
相关文章推荐
- mysql主从不同步时,怎么恢复
- 深入Java集合学习系列:LinkedHashMap的实现原理
- 一些网络相关问题的总结
- 图说函数模板右值引用参数(T&&)类型推导规则(C++11)
- C#和C++的区别
- mac 新电脑上安装使用adb
- 0x3f3f3f3f…编程中无穷大常量的设置技巧
- php分页类代码带分页样式效果(转)
- 2016.3.15作业
- java中基本数据类型与字符串的转换
- python Custom template tags and filters is not a valid tag library
- HDU 2602Bone Collector 01背包
- uva10746 (最小费用最大流)
- com.alibaba.dubbo.rpc.RpcException: Since you are
- 作业3:个人项目-词频统计
- 引发电气火灾火警的原因(转载)
- 第34讲项目2——麻烦的累加涨功夫(1)
- shell_wc(统计数目)、head(查看前几行)、tail(查看末尾几行)
- push过去 返回来一直少个view
- 第3周项目4(3)穷举法解决组合问题