剑指offer 数值的整数次方


class Solution {
public:
    double Power(double base, int exponent) {
        double res = 1;
        if(exponent == 0){
            if(base == 0){
                return -1;
            }
            else{
                return 1;
            }
        }
        else{
            for( int i = 0; i < abs(exponent); i++){
                res *= base;
            }
            if(exponent < 0){
                res = 1/res;
            }
        }
        return res;
    }
};
posted @ 2018-08-23 19:09  一条图图犬  阅读(87)  评论(0编辑  收藏  举报