当前位置:网站首页>剑指offer:数值的整数次方
剑指offer:数值的整数次方
2022-08-02 14:11:00 【超级码力奥】
直接上快速幂
原题链接:https://www.acwing.com/problem/content/description/26/
class Solution {
public:
double Power(double base, int exponent) {
typedef long long LL;
bool is_minus = exponent < 0;
double res = 1;
for(LL k = abs(LL(exponent)); k; k >>= 1)
{
if(k & 1) res *= base;
base *= base;
}
if(is_minus) res = 1 / res;
return res;
}
};
class Solution(object):
def Power(self, base, exponent):
""" :type base: float :type exponent: int :rtype: float """
is_minus = exponent < 0
res = 1
k = abs(exponent)
while k:
if k & 1:
res *= base
base = base * base
k >>= 1
if is_minus:
res = 1 / res
return res
边栏推荐
猜你喜欢

Detailed introduction to the hierarchical method of binary tree creation

How to reinstall Win7 system with U disk?How to reinstall win7 using u disk?

为vscode配置clangd

mysql的索引结构为什么选用B+树?

Redis common interview questions

What should I do if the Win10 system sets the application identity to automatically prompt for access denied?

Do Windows 10 computers need antivirus software installed?

GMP scheduling model of golang

Exotic curiosity-a solution looking - bit operations

轻量化AlphaPose
随机推荐
word方框怎么打勾?
MATLAB drawing command fimplicit detailed introduction to drawing implicit function graphics
Introduction to MATLAB drawing functions ezplot explanation
Win11 computer off for a period of time without operating network how to solve
Article pygame drag the implementation of the method
Open the door of electricity "Circuit" (1): voltage, current, reference direction
How to solve Win11 without local users and groups
Fast advanced TypeScript
Letter combination of LeetCode2 phone number
3.用户上传头像
将SSE指令转换为ARM NEON指令
推开机电的大门《电路》(二):功率计算与判断
二叉排序树与 set、map
The SSE instructions into ARM NEON
Mysql connection error solution
casbin模型
Codeforces Round #605 (Div. 3)
Configure clangd for vscode
第二十七章:时间复杂度与优化
Redis常见面试题