50. Pow(x, n)
Description
Implement pow(x, n), which calculates x
raised to the power n
(i.e., x^n
).
Example 1:
1 | Input: x = 2.00000, n = 10 |
Example 2:
1 | Input: x = 2.10000, n = 3 |
Example 3:
1 | Input: x = 2.00000, n = -2 |
Constraints:
-100.0 < x < 100.0
-2^31 <= n <= 2^31-1
n
is an integer.- Either
x
is not zero orn > 0
. -10^4 <= x^n <= 10^4
Hints/Notes
- 2024/12/20
- fast power
- 0x3Fâs solution
Solution
Language: C++
1 | class Solution { |