Problem
Problem page: https://leetcode.com/problems/valid-palindrome/
Topics: Two Pointers, String
Difficulty: Easy
Similar problems: (E) Palindrome Linked List
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama"is a palindrome.
"race a car"is not a palindrome.Note:
Have you consider that the string might be empty? This is a good question to > ask during an interview.For the purpose of this problem, we define empty string as valid palindrome.
Analysis
Check whether the string is a palindrome. Only letters and digits count, and case doesn't matter. Don't forget to check whether the string passed in is empty. This might be one of the biggest differences between interview coding questions and ACM contest problems: you have to think about all sorts of unusual cases and check what happens at the boundaries. It's a simple problem. The interviewer is looking at how the candidate approaches programming as a whole. Knowing a particular clever algorithm is only part of that.
Code
1 | class Solution: |
Article link: https://xnerv.wang/en/leetcode-valid-palindrome/
