All problemsBack
Valid Palindrome
easyA 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.
Given a string s, return true if it is a palindrome, or false otherwise.
Test Cases
Copy an input into themain harness and Run to verifyInput
s = "A man, a plan, a canal: Panama"Expected Output
trueExplanation: "amanaplanacanalpanama" is a palindrome.
Input
s = "race a car"Expected Output
falseInput
s = " "Expected Output
trueExplanation: After removing non-alphanumerics, s becomes an empty string, which reads the same both ways.
Constraints
- 1 <= s.length <= 2 * 10^5
- s consists only of printable ASCII characters.
Hints
Hint 1 — click to reveal
Two pointers from both ends, skipping non-alphanumerics.
Hint 2 — click to reveal
Compare lowercased characters as the pointers walk inward.
Java Compiler
Powered by OneCompiler. Starter code loads automatically — edit and hit Run.