[Leetcode] #50 Pow(x, n)

来源:互联网 发布:快刀软件 编辑:程序博客网 时间:2024/05/22 16:38

Discription:

Implement pow(x, n).


Solution:

double myPow(double x, int n) {if (n == 0) return 1.0;if (n < 0){if (n == INT_MIN)return 1.0 / (myPow(x, INT_MAX)*x);elsereturn 1.0 / myPow(x, -1 * n);}double temp = myPow(x, n >> 1);if (n & 1 == 1)return x*temp*temp;else return temp*temp;}


原创粉丝点击