class Solution {
public:
double pow(double x, int n)
{
double a=1;
if(n==0)return 1;
if(x==1)return 1;
if(x==-1)
{
if(n&1)return -1;
else return 1;
}
int absn=abs(n);
a=power(x,absn);
if(n<0)
{
a=1/a;
}
return a;
}
double power(double x,int n)
{
double result=1;
if(n==1)return x;
if(n&1)
{
result*=x;
n=n-1;
}
double temp=power(x,n>>1);
result=result*temp*temp;
return result;
}
};

leetcode power(x,n)的更多相关文章

  1. [LeetCode] Power of Four 判断4的次方数

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...

  2. [LeetCode] Power of Three 判断3的次方数

    Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...

  3. [LeetCode] Power of Two 判断2的次方数

    Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...

  4. LeetCode Power of Four

    原题链接在这里:https://leetcode.com/problems/power-of-four/ 题目: Given an integer (signed 32 bits), write a ...

  5. LeetCode Power of Three

    原题链接在这里:https://leetcode.com/problems/power-of-three/ 与Power of Two类似.检查能否被3整除,然后整除,再重复检查结果. Time Co ...

  6. Leetcode Power of Two

    Given an integer, write a function to determine if it is a power of two. 题目意思: 给定一个整数,判断是否是2的幂 解题思路: ...

  7. Leetcode Power of two, three, four

    Given an integer, write a function to determine if it is a power of two. Hint: Could you solve it in ...

  8. LeetCode——Power of Two

    Description: Given an integer, write a function to determine if it is a power of two. public class S ...

  9. [LeetCode]Power of N

    题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是 ...

随机推荐

  1. wxPython中添加窗口标题图标

    这种添加方法可以避免要将应用程序和图标放在同一个目录,可以实现从模块中读取图标 #用于从module中读取ico,避免了要在程序所在路径附上此ico exeName = win32api.GetMod ...

  2. TM1668 Led 驱动芯片源程序

    #define P_1668DAT_In RA0 //数据输入端口 #define P_1668DAT LATA0 //数据输出端口 #define P_1668CLK LATA1 #define P ...

  3. Unity3D中Prefab

    Prefab概念: Prefab是一种资源类型--存储在项目视图中的一种可反复使用的游戏对象.因而当游戏中须要非常多反复使用的对象.资源等时,Prefab就有了用武之地.它拥有下面特点: 能够放到多个 ...

  4. UVM:8.2.4 factory 机制的调试

    1.UVM提供了print_override_info 帮助debug.以上节new_monitor 为例: 2.调用print_override_info : 结果: 实际调用debug_creat ...

  5. 阿里云部署Docker(7)----将容器连接起来

    路遥知马力.日久见人心.恩. 该坚持的还是要坚持. 今天看到一个迅雷的师弟去了阿里,祝福他,哎,尽管老是被人家捧着叫大牛.我说不定通过不了人家的面试呢.哎,心有惭愧. 本文为本人原创,转载请表明来源: ...

  6. Java数据库连接代码集合(转)

    Java数据库连接接口(JDBC)是Java里定义的一套用于数据库连接和操作的API的集合.有不同的数据库厂商提供这套接口的实现类,对于 Java程序员来说,程序员不需要关心数据库的底层的实现,统一的 ...

  7. 去掉cajviewer 右上角的“中国知网数字出版物超市

    cajviewer软件是一款可以提取pdf字码的软件(即使pdf是扫描版的) 下面是转的一个博文可以去除软件右上角图标的方法: 去掉cajviewer 7.1.2右上角的“中国知网数字出版物超市” 1 ...

  8. 【NodeJs】Ctrl+C在Linux平台和Windows平台下的TCP连接中的不同表现

    Linux平台:CentOS release 6.5 (Final) Windows平台:Windows 7 旗舰版 服务器端代码如下: var net = require('net'); var s ...

  9. Mybaitis配置总结

    在mybatis-config.xml中配置分页插件,插件配置必须放在mapper前面 <plugins> <plugin interceptor="com.rrtong. ...

  10. css 导航条 布局

    导航条(简单易用的导航) <!DOCTYPE html> <html> <head> <style> ul { list-style-type:none ...