当前位置:网站首页>Sword finger offer 16 Integer power of numeric value
Sword finger offer 16 Integer power of numeric value
2022-07-03 12:58:00 【Hiccup~~~~】
The finger of the sword Offer 16. Integer power of value
Medium difficulty 310
Realization pow(x, n) , Computation x Of n Power function ( namely ,xn). Do not use library functions , At the same time, there is no need to consider the problem of large numbers .
Example 1:
Input :x = 2.00000, n = 10 Output :1024.00000
Example 2:
Input :x = 2.10000, n = 3 Output :9.26100
Example 3:
Input :x = 2.00000, n = -2 Output :0.25000 explain :2-2 = 1/22 = 1/4 = 0.25
Tips :
- -100.0 < x < 100.0
- -231 <= n <= 231-1
- -104 <= xn <= 104
Ideas
- Fast power
- Long N=n
- x=1/x;
Code
class Solution {
public:
double myPow(double x, int n) {
long N=n; // Easy conversion n,-2147483648 Can also be converted to a positive number
double res=1.0;
if(n<0){
N=-N;
x=1/x; // During calculation , There is no need to make judgment
}
while(N){
int a=N%2;
N>>=1;
if(a==1) res*=x;
x*=x;
}
return res;
}
};
边栏推荐
- 最新版抽奖盲盒运营版
- Airflow installation jump pit
- Kung Fu pays off, and learning is done
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
- Brief introduction to mvcc
- 【数据库原理复习题】
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
- Openstack node address change
- context. Getexternalfilesdir() is compared with the returned path
- Cache penetration and bloom filter
猜你喜欢
并网-低电压穿越与孤岛并存分析
低代码平台国际化多语言(i18n)技术方案
最新版盲盒商城thinkphp+uniapp
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
[network counting] Chapter 3 data link layer (2) flow control and reliable transmission, stop waiting protocol, backward n frame protocol (GBN), selective retransmission protocol (SR)
自抗扰控制器七-二阶 LADRC-PLL 结构设计
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹
T430 toss and install OS majave 10.14
【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
随机推荐
【Colab】【使用外部数据的7种方法】
initial、inherit、unset、revert和all的区别
[Exercice 5] [principe de la base de données]
剑指 Offer 12. 矩阵中的路径
C graphical tutorial (Fourth Edition)_ Chapter 15 interface: interfacesamplep268
Airflow installation jump pit
我的创作纪念日:五周年
I'm too lazy to write more than one character
Attack and defense world mobile--ph0en1x-100
Glide question you cannot start a load for a destroyed activity
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
Xctf mobile--app1 problem solving
Harmonic current detection based on synchronous coordinate transformation
[judgment question] [short answer question] [Database Principle]
[ArcGIS user defined script tool] vector file generates expanded rectangular face elements
sitesCMS v3.1.0发布,上线微信小程序
【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】
最新版抽奖盲盒运营版
Ali & ant self developed IDE
高效能人士的七个习惯