forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.py
More file actions
30 lines (25 loc) · 606 Bytes
/
11.py
File metadata and controls
30 lines (25 loc) · 606 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
# -*- coding:utf-8 -*-
class Solution:
def Power(self, base, exponent):
# write code here
if base == 0:
return 0
if exponent == 0:
return 1
flag = 1
if exponent < 0:
flag = 0
exponent = -exponent
sum = 1.0
tmp = base
while (exponent > 0):
if exponent & 1 == 1:
sum *= tmp
tmp *= tmp
exponent = exponent >> 1
if flag == 0:
sum = 1 / sum
return sum
solution = Solution()
# 00..11
print solution.Power(3, 2)