LeetCode Pow(x, n)

思路:二分求,,注意正负号就是了。

class Solution {public:double cal(double x, int n) {if (n == 0)return 1.0;double tmp = pow(x, n>>1);if (n & 1)return tmp * tmp * x;else return tmp * tmp;}double pow(double x, int n) {if (n < 0)return 1.0 / cal(x, -n);else return cal(x, n);}};

积极思考造成积极人生,消极思考造成消极人生。

LeetCode Pow(x, n)

相关文章:

你感兴趣的文章:

标签云: