Search topics...

Pow(x, n)

medium
mathTime: O(log n)Space: O(1)Frequency: 3

Implement pow(x, n), which calculates x raised to the power n.

Example 1:

Input: x = 2.0, n = 10
Output: 1024.0

Example 2:

Input: x = 2.1, n = 3
Output: 9.261

Example 3:

Input: x = 2.0, n = -2
Output: 0.25
Explanation: 2^(-2) = 1/(2^2) = 0.25
bit-manipulation