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:
Saksham Chawla 2023-10-02 19:59:06 +05:30 committed by GitHub
parent 9640a4041a
commit 89a65a8617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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