JS力扣刷题50. Pow(x, n)
思路:二分递归
var myPow = function(x, n) {
if(n == 0)return 1;
function f(x, n){
if(n == 1)return x;
if(n % 2 == 0)return f(x, Math.floor(n / 2)) ** 2;
else return f(x, Math.floor(n / 2)) ** 2 * x;
}
if(n > 0)return f
原创
2022-04-14 16:12:00 ·
112 阅读 ·
0 评论