Handle gcd(0, 0) edge case (#14215)

* Use TypeError for non-string input in count_vowels

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix docstring and improve input validation in kth_lexicographic_permutation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Handle gcd(0, 0) edge case

* Update kth_lexicographic_permutation.py

* Update count_vowels.py

* Update greatest_common_divisor.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
Yaadhuu
2026-03-09 09:38:51 +05:30
committed by GitHub
parent 81fcb90f7b
commit 84b59c8781

View File

@@ -30,6 +30,8 @@ def greatest_common_divisor(a: int, b: int) -> int:
3
>>> greatest_common_divisor(-3, -9)
3
>>> greatest_common_divisor(0, 0)
0
"""
return abs(b) if a == 0 else greatest_common_divisor(b % a, a)
@@ -50,6 +52,8 @@ def gcd_by_iterative(x: int, y: int) -> int:
1
>>> gcd_by_iterative(11, 37)
1
>>> gcd_by_iterative(0, 0)
0
"""
while y: # --> when y=0 then loop will terminate and return x as final GCD.
x, y = y, x % y