Valid Palindrome
You get a string. Find out whether it reads the same left to right and right to left once you keep only the letters and digits and ignore upper and lower case. Our example: "Taco, cat!" — yes, it is a palindrome.
- input
s: a string of letters, digits, spaces and punctuation.- returns
trueifsreads the same both ways once every character that is not a letter or a digit is dropped and uppercase letters are made lowercase; otherwisefalse.- constraints
- 1 ≤ s.length ≤ 5000
- s: printable ASCII characters
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @return {boolean}
*/
function isPalindrome(s) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more two pointers problems
- 26Remove Duplicates from Sorted ArrayEasysolve
- 283Move ZeroesEasysolve
- 88Merge Sorted ArrayEasysolve
- 27Remove ElementEasysolve
- 392Is SubsequenceEasysolve
- 167Two Sum II - Input Array Is SortedMediumsolve
- 153SumMediumsolve
- 11Container With Most WaterMediumsolve
- 80Remove Duplicates from Sorted Array IIMediumsolve
- 189Rotate ArrayMediumsolve
- 151Reverse Words in a StringMediumsolve
- 5Longest Palindromic SubstringMediumsolve
- 42Trapping Rain WaterHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.