You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
public:doublemyPow(double x, int n) {
if (n == 0) return1.0;
unsignedint m = n;
if (n < 0) {
m = ~m + 1;
x = 1/x;
}
double res = 1.0;
while (m) {
if (m&1) {
res *= x;
}
x *= x;
m = m >> 1;
}
return res;
}
};
The text was updated successfully, but these errors were encountered:
实现 pow(x, n) ,即计算 x 的 n 次幂函数(即,xn)。
示例 1:
示例 2:
示例 3:
提示:
解法:
快速幂。代码如下:
The text was updated successfully, but these errors were encountered: