Skip to content

Pow(x,n) ​

Pow(x,n) — LeetCode

Implement pow(x, n), which raises x to the integer power n, in logarithmic time.

Approach ​

x^n = x^(n/2) * x^(n/2) * x^(n%2) Recursively do power of n/2 and n%2. Multiply them together and pass back up.

Remarks ​

Pasted image 20260711105919.png