Skip to content

Commit

Permalink
Add typing to binary_exponentiation.py (TheAlgorithms#9471)
Browse files Browse the repository at this point in the history
* Add typing to binary_exponentiation.py

* Update binary_exponentiation.py

* float to int division change as per review
  • Loading branch information
saksham-chawla authored Oct 2, 2023
1 parent 9640a40 commit 89a65a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions maths/binary_exponentiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# Time Complexity : O(logn)


def binary_exponentiation(a, n):
def binary_exponentiation(a: int, n: int) -> int:
if n == 0:
return 1

elif n % 2 == 1:
return binary_exponentiation(a, n - 1) * a

else:
b = binary_exponentiation(a, n / 2)
b = binary_exponentiation(a, n // 2)
return b * b


Expand Down

0 comments on commit 89a65a8

Please sign in to comment.