当前位置:网站首页>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;
}
};边栏推荐
- 「经验」浅谈聚类分析在工作中的应用
- Deep understanding of JVM (V) - garbage collection (II)
- 基於SSH的網上商城設計
- C语言结构体
- Partition marble (multiple knapsack + binary optimization)
- Vulnerability recurrence ----37. Apache unomi Remote Code Execution Vulnerability (cve-2020-13942)
- Advanced customization of uni app [day13]
- Customer relationship CRM management system based on SSH
- Research on the principle of Tencent persistence framework mmkv
- Post penetration file system + uploading and downloading files
猜你喜欢

Apache parsing vulnerability (cve-2017-15715)_ Vulnerability recurrence

Dropout: immediate deactivation

It's not easy to say I love you | use the minimum web API to upload files

What will be the game changes brought about by the meta universe?

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

MySQL advanced - index optimization (super detailed)

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

Inventory in the first half of 2022: summary of major updates and technical points of 20+ mainstream databases

ABAP-发布Restful服务

What does software testing need to learn? Test learning outline sorting
随机推荐
Post MSF infiltration summary
[binary tree] preorder traversal to construct binary search tree
VS code 树视图 treeView
【二叉树】前序遍历构造二叉搜索树
Redis (III) - transaction
Hcip (Huawei Senior Network Security Engineer) (Experiment 8) (MPLS basic experiment)
ASP. Net authentication code login
Redis (V) - advanced data types
Elastic 8.0: opening a new era of speed, scale, relevance and simplicity
Do you write API documents or code first?
Redis (IX) - enterprise level solution (II)
Distributed machine learning: model average Ma and elastic average easgd (pyspark)
Communication network electronic billing system based on SSH
Vulnerability recurrence ----- 35. Uwsgi PHP directory traversal vulnerability (cve-2018-7490)
Alexnet of CNN classic network (Theory)
使用excel快速生成sql语句
Redis - persistent RDB and persistent AOF
Redis (II) -- persistence
Rhai - Rust 的嵌入式脚本引擎
Openlayers roller shutter map