当前位置:网站首页>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;
}
};
边栏推荐
- Differences and connections between final and static
- Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
- 2022-01-27 research on the minimum number of redis partitions
- [comprehensive question] [Database Principle]
- OpenHarmony应用开发之ETS开发方式中的Image组件
- 【数据库原理及应用教程(第4版|微课版)陈志泊】【第七章习题】
- GCN thinking - word2vec directly calculates text classification
- 【习题五】【数据库原理】
- Kotlin notes - popular knowledge points asterisk (*)
- [combinatorics] permutation and combination (the combination number of multiple sets | the repetition of all elements is greater than the combination number | the derivation of the combination number
猜你喜欢

Social community forum app ultra-high appearance UI interface

【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】

Powerful avatar making artifact wechat applet

Analysis of the influence of voltage loop on PFC system performance

sitesCMS v3.1.0发布,上线微信小程序

Leetcode234 palindrome linked list

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈

Node. Js: use of express + MySQL

Huffman coding experiment report
![[ArcGIS user defined script tool] vector file generates expanded rectangular face elements](/img/39/0b31290798077cb8c355fbd058e4d3.png)
[ArcGIS user defined script tool] vector file generates expanded rectangular face elements
随机推荐
Nodejs+Express+MySQL实现登陆功能(含验证码)
Harmonic current detection based on synchronous coordinate transformation
Solve the problem of VI opening files with ^m at the end
Ali & ant self developed IDE
2022-01-27 redis cluster technology research
[judgment question] [short answer question] [Database Principle]
Glide 4.6.1 API initial
initial、inherit、unset、revert和all的区别
Airflow installation jump pit
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹
Export the entire Oracle Database
剑指 Offer 16. 数值的整数次方
强大的头像制作神器微信小程序
[exercise 6] [Database Principle]
I'm too lazy to write more than one character
【数据库原理及应用教程(第4版|微课版)陈志泊】【第三章习题】
ORM use of node -serialize
Swift return type is a function of function
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: what is entrustment? P238
Differences and connections between final and static