当前位置:网站首页>20220603数学:Pow(x,n)
20220603数学:Pow(x,n)
2022-07-03 09:20:00 【丿SeeYouAgain】
题目描述:实现 pow(x, n) ,即计算 x
的 n
次幂函数(即,x^n
)。
编码实现:
public static double myPow(double x, int n) {
double result = 1.0;
for (int i = n; i != 0; i /= 2) {
if (i % 2 != 0) {
result *= x;
}
x *= x;
}
return n < 0 ? 1 / result : result;
}
边栏推荐
- LeetCode - 705 设计哈希集合(设计)
- Emballage automatique et déballage compris? Quel est le principe?
- Openeuler kernel technology sharing - Issue 1 - kdump basic principle, use and case introduction
- Basic use and actual combat sharing of crash tool
- LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
- Timer and counter of 51 single chip microcomputer
- LeetCode - 919. 完全二叉树插入器 (数组)
- Installation and removal of MySQL under Windows
- Opencv feature extraction - hog
- LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
猜你喜欢
YOLO_ V1 summary
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
LeetCode - 5 最长回文子串
Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
yocto 技术分享第四期:自定义增加软件包支持
The underlying principle of vector
LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
el-table X轴方向(横向)滚动条默认滑到右边
2. Elment UI date selector formatting problem
随机推荐
[keil5 debugging] warning:enumerated type mixed with other type
STM32 general timer output PWM control steering gear
When the reference is assigned to auto
Opencv histogram equalization
yocto 技術分享第四期:自定義增加軟件包支持
Octave instructions
Basic knowledge of communication interface
Application of 51 single chip microcomputer timer
CV learning notes - deep learning
Design of charging pile mqtt transplantation based on 4G EC20 module
03 fastjason solves circular references
2021-11-11 standard thread library
(2) New methods in the interface
LeetCode - 673. 最长递增子序列的个数
My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
MySQL root user needs sudo login
It is difficult to quantify the extent to which a single-chip computer can find a job
LeetCode - 919. 完全二叉树插入器 (数组)
Adaptiveavgpool1d internal implementation
There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way