Search topics...
All Problems
Was this helpful?
MediummathExpected: O(log n) time, O(1) space
bit-manipulation

Problem

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
Reference solution unlocks after your first submission
Loading...