Skip to content

Commit fcf7918

Browse files
authored
Update power.py
1 parent 9e6c74c commit fcf7918

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

divide_and_conquer/power.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def actual_power(a: int, b: int):
1+
def actual_power(a: int, b: int)-> int:
22
"""
33
Function using divide and conquer to calculate a^b.
44
It only works for integer a,b.
@@ -22,9 +22,9 @@ def actual_power(a: int, b: int):
2222
half = actual_power(a, b // 2)
2323

2424
if (b % 2) == 0:
25-
return actual_power(a, int(b / 2)) * actual_power(a, int(b / 2))
26-
else:
2725
return half * half
26+
else:
27+
return a * half * half
2828

2929

3030
def power(a: int, b: int) -> float:

0 commit comments

Comments
 (0)