Return True if s is a palindrome otherwise return False. >>> all(is_palindrome_traversal(key) == value for key, value in test_data.items()) True
(s: str)
| 38 | |
| 39 | |
| 40 | def is_palindrome_traversal(s: str) -> bool: |
| 41 | """ |
| 42 | Return True if s is a palindrome otherwise return False. |
| 43 | |
| 44 | >>> all(is_palindrome_traversal(key) == value for key, value in test_data.items()) |
| 45 | True |
| 46 | """ |
| 47 | end = len(s) // 2 |
| 48 | n = len(s) |
| 49 | |
| 50 | # We need to traverse till half of the length of string |
| 51 | # as we can get access of the i'th last element from |
| 52 | # i'th index. |
| 53 | # eg: [0,1,2,3,4,5] => 4th index can be accessed |
| 54 | # with the help of 1st index (i==n-i-1) |
| 55 | # where n is length of string |
| 56 | return all(s[i] == s[n - i - 1] for i in range(end)) |
| 57 | |
| 58 | |
| 59 | def is_palindrome_recursive(s: str) -> bool: |
nothing calls this directly
no outgoing calls
no test coverage detected