class Solution {
public double Power(double base, int exponent) {
boolean flag = true;
if(exponent < 0){
flag = false;
exponent = -1 * exponent;
}
double res = 1;
while(exponent != 0){
if((exponent & 1) != 0){
res = res*base;
}
exponent = exponent >> 1;
base = base*base;
}
if(flag)return res;
else return 1/res;
}
}
exponent = -1 * exponent; 现在应该用long存了,测试数据中有-2147483648取负号会爆
确实,leetcode的测试数据有点东西的
该写法在LeetCode无法通过
leetcode 题目要求是否一致呢