#125
Easy Algorithms Valid palindrome
Two Pointers String
52.8% acceptance
Jan 12, 2026
11470
8633
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.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn is_palindrome(s: String) -> bool {
let chars: Vec<char> = s.chars()
.filter(|c| c.is_alphanumeric())
.map(|c| c.to_ascii_lowercase())
.collect();
let mut left = 0;
let mut right = chars.len();
while left < right {
right -= 1;
if chars[left] != chars[right] {
return false;
}
left += 1;
}
true
}
}