网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  剑指offer-数值的整数次方

剑指offer-数值的整数次方

分类: IT文章 • 2025-01-31 19:11:43

题目描述

给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。保证base和exponent不同时为0

class Solution {
public:
    
    double Power(double base, int exponent) {
        if(base==1.0) return 1.0;
        if(exponent==0) return 1.0;
        double temp=1.0;
        if(exponent>0)
        {
            while(exponent)
            {
                temp = temp*base;
                exponent--;
            } 
        }
        else{
            
            while(exponent)
            {
                temp =temp/base;
                exponent++;
            } 
        }
        return temp;
    }
    
};

相关推荐

  • 剑指offer-字符串转为int数字,不用+来相加两个数,不用新增变量来交换数,在递增序列中找和为s的两个数字and找和为s的序列。 字符串转为int数字 不用+来相加两个数 PS.不用新增变量来交换数 在递增序列中找和为s的两个数字and找和为s的序列。
  • 剑指offer-在一维数组中找重复出现的数。
  • 【面试题11】数值的整数次方
  • 剑指offer-数值的整数次方
  • 剑指offer-和为s的两个数
  • 剑指offer-数组中只出现一次的数字
  • 剑指offer-和为s的连续正数序列
  • 剑指Offer——表示数值的字符串
  • 剑指offer之关于整数的处理
  • 剑指offer-栈的压入、弹出序列 0 题目 1 分析
  • 剑指offer39-平衡二叉树
  • 查找算法
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号