数值的整数次方-个人解法

数值的整数次方

http://www.nowcoder.com/questionTerminal/1a834e5e3e1a4b7ba251417554e07c00

数值的整数次方

  • 没有做exponent为0或者1的判断
  • 只做了exponent正负的判断
public class Solution {
    public double Power(double base, int exponent) {
        double res = 1;
        if(exponent>=0){
            while(exponent-->0) res *=base;
        }else{
            while(exponent++<0) res *=base;
            res=1/res;
        }
        return res;
  }
}
全部评论

相关推荐

八极星:有什么不能问的,(/_\),这又不是多珍贵的机会,你有什么可失去的
点赞 评论 收藏
分享
11-13 14:37
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务