Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
impl Solution {
pub fn is_palindrome(s: String) -> bool {
let mut chars = s
.chars()
.filter(|c| c.is_alphanumeric())
.map(|c| c.to_lowercase());
while let (Some(next), Some(next_back)) = (chars.next(), chars.next_back()) {
if next != next_back {
return false;
}
}
// true
(0..)
.scan((0, 1), |acc, _| {
*acc = (acc.1, acc.0 + acc.1);
Some(acc.0)
})
.nth(n as usize)
.unwrap()
tree1.val == tree2.val &&
is_symmetric_helper(&tree1.left, &tree2.right) &&
is_symmetric_helper(&tree1.right, &tree2.left)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.