medium
Pow(x, n)
Implement a function computing x raised to the integer power n, where n may be negative or zero, using far fewer than |n| multiplications.
Constraints
- -100 < x < 100
- -2^31 ≤ n ≤ 2^31 - 1
- The result fits in a double
Examples
in: x = 2, n = 10
out: 1024
in: x = 2, n = -2
out: 0.25
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.