1
Fork 0
leetcode/source/valid_palindrome/mod.rs

15 lines
340 B
Rust
Raw Permalink Normal View History

2022-04-08 22:32:20 +00:00
pub fn is_palindrome(string: String) -> bool {
let normalized = string.chars().filter_map(|c| {
if char::is_alphanumeric(c) {
Some(c.to_ascii_lowercase())
} else {
None
}
});
let regular = normalized.clone().collect::<String>();
let reversed = normalized.rev().collect::<String>();
regular == reversed
}