Skip to content

Commit 5d46d76

Browse files
Update palindrome.py
1 parent d3485f4 commit 5d46d76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

recursion/palindrome.py

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ def palindrome_helper(s: str, start: int, end: int) -> bool:
1919
print(palindrome_checker(str2))
2020

2121

22+
def palindrome_checker_iterative(string:str) -> bool:
23+
is_palindrome: bool = True
24+
start = 0
25+
end = len(string) - 1
26+
27+
while start < end and is_palindrome:
28+
if string[start] != string[end]:
29+
is_palindrome = False
30+
start += 1
31+
end -= 1
32+
33+
return is_palindrome
34+
35+
36+
print(palindrome_checker_iterative(str1))
37+
print(palindrome_checker_iterative(str2))
38+
39+
2240
def palindrome_checker_slicing(string: str) -> bool:
2341
if len(string) <= 1:
2442
return True

0 commit comments

Comments
 (0)