50. Pow(x, n)
https://leetcode.com/problems/powx-n/description/
solution
快速幂: recursive
n为奇数,x^n = x(x^2)^(n//2)
n为偶数,x^n = (x^2)^(n//2)
时间复杂度:O(log(n)) 空间复杂度:O(1)
非递归: iterative
follow up
时间复杂度:O(n) 空间复杂度:O(1)
Last updated
https://leetcode.com/problems/powx-n/description/
快速幂: recursive
n为奇数,x^n = x(x^2)^(n//2)
n为偶数,x^n = (x^2)^(n//2)
时间复杂度:O(log(n)) 空间复杂度:O(1)
非递归: iterative
时间复杂度:O(n) 空间复杂度:O(1)
Last updated