当前位置:网站首页>剑指 Offer 16. 数值的整数次方
剑指 Offer 16. 数值的整数次方
2022-06-30 16:53:00 【anieoo】
原题链接:剑指 Offer 16. 数值的整数次方
solution:
快速幂
①计算 x 的n次方是将 n个 x 连乘,效率比较低,会超时。
② 乘法具有结合律,考虑每次将一部分连乘批量计算好,作为最终答案的一部分。
class Solution {
public:
typedef long long LL;
double myPow(double x, int n) {
bool is_minus = n < 0;
double res = 1;
for(LL k = abs(n);k;k >>= 1) {
if(k & 1) res *= x;
x *= x;
}
if(is_minus) return 1 / res;
return res;
}
};边栏推荐
- Hcip (Huawei Senior Network Security Engineer) (Experiment 8) (MPLS basic experiment)
- Taishan Office Technology Lecture: how to align and draw words of different sizes on the same line
- 基于SSH的客户关系CRM管理系统
- 零基础也能做Apple大片!这款免费工具帮你渲染、做特效、丝滑展示
- 漏洞复现----38、ThinkPHP5 5.0.23 远程代码执行漏洞
- Zero foundation can also be an apple blockbuster! This free tool can help you render, make special effects and show silky slides
- What does software testing need to learn? Test learning outline sorting
- Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
- MySQL advanced - index optimization (super detailed)
- Animesr: learnable degradation operator and new real world animation VSR dataset
猜你喜欢

Talk about the SQL server version of DTM sub transaction barrier function

Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole

漏洞复现----38、ThinkPHP5 5.0.23 远程代码执行漏洞

Daily interview 1 question - basic interview question of blue team - emergency response (1) basic idea process of emergency response +windows intrusion screening idea

基於SSH的網上商城設計

Deep understanding of JVM (II) - memory structure (II)

后渗透之文件系统+上传下载文件

Generate confrontation network, from dcgan to stylegan, pixel2pixel, face generation and image translation.

MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc

ASP. Net generate verification code
随机推荐
[sword finger offer] 52 The first common node of two linked lists
漏洞复现----37、Apache Unomi 远程代码执行漏洞 (CVE-2020-13942)
[BJDCTF2020]The mystery of ip|[CISCN2019 华东南赛区]Web11|SSTI注入
Php8.0 environment detailed installation tutorial
清华只能排第3?2022软科中国大学AI专业排名发布
Partition marble (multiple knapsack + binary optimization)
MSF后渗透总结
Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science
联想“双平台”运维解决方案 助力智慧医疗行业智慧管理能力全面提升
Deep understanding of JVM (I) - memory structure (I)
力扣解法汇总1175-质数排列
What will be the game changes brought about by the meta universe?
Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
autocad中文语言锁定只读警报怎么解决?
Redis (VIII) - enterprise level solution (I)
Type ~ storage ~ variable in C #
Send the injured baby for emergency medical treatment. Didi's driver ran five red lights in a row
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
基于eNSP的校园网设计的仿真模拟
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact