classSolution{public:doublemyPow(double x,int n){long a = n;if(abs(x)<1e-6&& n<0)return0.0;double res =1.0;// c++中负数的右移操作不是简单除2,所以a要先转换成非负if(n<0){
x =1/x;
a=-a;}while(a!=0){if(a&1==1)
res *= x;
x*=x;
a >>=1;}return res;}};
面试题16. 数值的整数次方(快速幂,清晰图解)class Solution {public: double myPow(double x, int n) { long a = n; if (abs(x)<1e-6 && n<0) return 0.0; double res = 1.0...