Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 25, 2019 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/9496a2ad72ff2bf15d275c8da3b87dcc to your computer and use it in GitHub Desktop.
Save rust-play/9496a2ad72ff2bf15d275c8da3b87dcc to your computer and use it in GitHub Desktop.
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