标签:
Implement pow(x, n).
class Solution { public: double myPow(double x, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n<0) { if(n==INT_MIN) return 1.0 / (myPow(x,INT_MAX)*x); else return 1.0 / myPow(x,-n); } if(n==0) return 1.0; double ans = 1.0 ; for(;n>0; x *= x, n>>=1) { if(n&1>0) ans *= x; } return ans; } };
标签:
原文地址:http://www.cnblogs.com/SpeakSoftlyLove/p/5184775.html