1 Star 0 Fork 0

wangzai/力扣算法面试题

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
50. Pow(x, n).cpp 471 Bytes
一键复制 编辑 原始数据 按行查看 历史
wangzai 提交于 2021-11-24 15:33 . 增加了50 Pow(x, n)
// 分类:数论
// Created by 旺崽 on 2021/11/24.
//
#include "bits/stdc++.h"
using namespace std;
class Solution {
public:
double myPow(double x, int n) {
double ans = 1, flag = 0, a = x;
long long e = n;
if (e < 0) e = -e, flag = 1;
while (e) {
if (e & 1) ans *= a;
a = a * a;
e >>= 1;
}
if (flag) return 1 / ans;
return ans;
}
};
int main() {
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qianlinyi/algorithmicQuestions.git
git@gitee.com:qianlinyi/algorithmicQuestions.git
qianlinyi
algorithmicQuestions
力扣算法面试题
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385