mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Add typing to binary_exponentiation.py (#9471)
* Add typing to binary_exponentiation.py * Update binary_exponentiation.py * float to int division change as per review
This commit is contained in:
parent
9640a4041a
commit
89a65a8617
@ -4,7 +4,7 @@
|
|||||||
# Time Complexity : O(logn)
|
# Time Complexity : O(logn)
|
||||||
|
|
||||||
|
|
||||||
def binary_exponentiation(a, n):
|
def binary_exponentiation(a: int, n: int) -> int:
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ def binary_exponentiation(a, n):
|
|||||||
return binary_exponentiation(a, n - 1) * a
|
return binary_exponentiation(a, n - 1) * a
|
||||||
|
|
||||||
else:
|
else:
|
||||||
b = binary_exponentiation(a, n / 2)
|
b = binary_exponentiation(a, n // 2)
|
||||||
return b * b
|
return b * b
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user