当前位置:网站首页>Sword finger offer 16 Integer power of numeric value
Sword finger offer 16 Integer power of numeric value
2022-06-30 18:28:00 【anieoo】
Original link : The finger of the sword Offer 16. Integer power of value
solution:
Fast power
① Calculation x Of n To the power of n individual x multiply continuously , Low efficiency , Will timeout .
② Multiplication has the law of association , It is considered to calculate a part of the serial multiplication batch each time , As part of the final answer .
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;
}
};边栏推荐
- 报名“互联网+”大赛华为云命题,诸多礼品任你拿!
- ASP. Net authentication code login
- Redis (IX) - enterprise level solution (II)
- Apple Watch无法开机怎么办?苹果手表不能开机解决方法!
- Vscode status bar statusbar
- MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc
- hdfs上的数据导入到clickhouse用什么方式最快呢?spark通过jdbc导入,还是hdfs
- Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases
- Research on the principle of Tencent persistence framework mmkv
- MySQL n'a pas pu trouver MySQL. Solution temporaire pour le fichier Sock
猜你喜欢

Animesr: learnable degradation operator and new real world animation VSR dataset

DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital

漏洞复现----37、Apache Unomi 远程代码执行漏洞 (CVE-2020-13942)

Another CVPR 2022 paper was accused of plagiarism, and Ping An insurance researchers sued IBM Zurich team

Redis (VIII) - enterprise level solution (I)

Redis (II) -- persistence

基于SSH的通讯网络电子计费系统

autocad中文语言锁定只读警报怎么解决?

Communication network electronic billing system based on SSH

每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
随机推荐
Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence
Redis (VI) - master-slave replication
Distributed machine learning: model average Ma and elastic average easgd (pyspark)
Flink series: checkpoint tuning
Rust 操控大疆可编程无人机 tello
使用excel快速生成sql语句
Redis (IV) - delete policy
基于eNSP的校园网设计的仿真模拟
基於SSH的網上商城設計
C language structure
. Net ORM framework hisql practice - Chapter 1 - integrating hisql
MySQL找不到mysql.sock文件的臨時解
depends工具查看exe和dll依赖关系
ABAP publish restful service
Simulation of campus network design based on ENSP
Nft: unlimited possibilities to open the era of encryption Art
Vulnerability recurrence ----- 38. Thinkphp5 5.0.23 Remote Code Execution Vulnerability
MySQL reports that the column timestamp field cannot be null
Flink系列:checkpoint调优
Small Tools(3) 集成Knife4j3.0.3接口文档