Implement is_palindrome(s). A string is a palindrome if it reads the same forward and backward after ignoring case and skipping every character that is not alphanumeric.
Use a left pointer and a right pointer. Advance each past any non-alphanumeric characters, then compare the two characters case-insensitively. If they differ, return False. Continue until the pointers meet. An empty string counts as a palindrome.
def two_sum_sorted(nums, target):
i, j = 0, len(nums) - 1
while i < j:
s = nums[i] + nums[j]
if s == target:
return (i, j)
elif s < target:
i += 1
else:
j -= 1
return None
def is_palindrome(s):
"""Return True if s is a palindrome ignoring case and non-alphanumerics."""
# TODO: use left and right pointers, skipping non-alphanumeric characters
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Implement is_palindrome(s). A string is a palindrome if it reads the same forward and backward after ignoring case and skipping every character that is not alphanumeric.
Use a left pointer and a right pointer. Advance each past any non-alphanumeric characters, then compare the two characters case-insensitively. If they differ, return False. Continue until the pointers meet. An empty string counts as a palindrome.
Press Run Tests or ββ© to check your solution.