leetcode50 Pow(x, n)

 1 """
 2 Implement pow(x, n), which calculates x raised to the power n (xn).
 3 Example 1:
 4 Input: 2.00000, 10
 5 Output: 1024.00000
 6 Example 2:
 7 Input: 2.10000, 3
 8 Output: 9.26100
 9 Example 3:
10 Input: 2.00000, -2
11 Output: 0.25000
12 Explanation: 2-2 = 1/22 = 1/4 = 0.25
13 """
14 class Solution:
15     def myPow(self, x, n):
16         if n < 0:
17             x = 1 / x  # Ingenious converted n <0 
18 is              n-= - n-
 . 19          RES = 1.0
 20 is          the while n-:
 21 is              IF ! N-% 2 = 0:   # n-&. 1 the operational advanced writing, a little faster 
22 is                  RES * = X
 23 is          * = X X
 24          n-2 = n-//   # n->>. 1 = 
25          return RES

 

Guess you like

Origin www.cnblogs.com/yawenw/p/12364656.html