Valid Palindrome
Easy · Two Pointers, String
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Example 1
Input: s = "A man, a plan, a canal: Panama" Output: true
"amanaplanacanalpanama" is a palindrome.
Example 2
Input: s = "race a car" Output: false
"raceacar" is not a palindrome.
Example 3
Input: s = " " Output: true
s is an empty string "" after removing non-alphanumeric characters. Since an empty string reads the same forward and backward, it is a palindrome.
Constraints
- 1 <= s.length <= 2 * 105
- s consists only of printable ASCII characters.
Starter code (python)
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
Related problems
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
- Container With Most Water (Medium)
Previous: Best Time to Buy and Sell Stock III · Next: Word Ladder · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.