Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions strings/palindrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def is_palindrome(s: str) -> bool:

>>> all(is_palindrome(key) == value for key, value in test_data.items())
True
>>> is_palindrome("")
True
"""

start_i = 0
Expand All @@ -43,6 +45,8 @@ def is_palindrome_traversal(s: str) -> bool:

>>> all(is_palindrome_traversal(key) == value for key, value in test_data.items())
True
>>> is_palindrome_traversal("")
True
"""
end = len(s) // 2
n = len(s)
Expand All @@ -62,6 +66,8 @@ def is_palindrome_recursive(s: str) -> bool:

>>> all(is_palindrome_recursive(key) == value for key, value in test_data.items())
True
>>> is_palindrome_recursive("")
True
"""
if len(s) <= 1:
return True
Expand All @@ -77,6 +83,8 @@ def is_palindrome_slice(s: str) -> bool:

>>> all(is_palindrome_slice(key) == value for key, value in test_data.items())
True
>>> is_palindrome_slice("")
True
"""
return s == s[::-1]

Expand All @@ -96,6 +104,10 @@ def is_palindrome_ignore_case_and_spaces(s: str) -> bool:
True
>>> is_palindrome_ignore_case_and_spaces("")
True
>>> is_palindrome_ignore_case_and_spaces(" !?. ")
True
>>> is_palindrome_ignore_case_and_spaces("1a2")
False
"""
s = "".join(char.lower() for char in s if char.isalnum())
return s == s[::-1]
Expand Down
Loading