GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/050_Pow(x, n).py at master · qiyuangong/leetcode Expand file tree/ Copy path050_Pow(x, n).pyMore file actions 31 lines (30 loc) · 811 Bytes / Copy path050_Pow(x, n).pyFile metadata and controls31 lines (30 loc) · 811 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 class Solution: # def myPow(self, x, n): # """ # :type x: float # :type n: int # :rtype: float # """ # if n == 0: # return 1 # temp = pow(x, n / 2) # if n % 2 == 0: # return temp * temp # else: # return temp * temp * x def myPow(self, x, n): # https://leetcode.com/discuss/93413/iterative-log-n-solution-with-clear-explanation # 9 = 2^3 + 2^0 = 1001 # x^9 = x^(2^3)*x(2^0) # multiple x^i when i place is 1 if n == 0: return 1 res ,curr = 1, abs(n) while curr > 0: if curr & 1 == 1: res *= x curr >>= 1 x *= x if n < 0: return 1 / res return res |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |