← 返回 bytedance 的题目列表Implement Power Function
类型:online_judge
bytedance
Implement a function myPow(x, n) to calculate the n-th power of a floating-point number x. Note that n can be negative, so you need to consider inverse powers. The solution should have a time complexity of O(log n).
Input:
A floating-point number x in the range [-100.0, 100.0]
An integer n in the range [-2^31, 2^31 - 1]
Output:
A floating-point number representing the n-th power of x.
Example:
Input: x = 2.0, n = 10
Output: 1024.0
Input: x = 2.1, n = 3
Output: 9.261
Input: x = 2.0, n = -2
Output: 0.25
Example
Input
2.0
10