Created
August 25, 2019 05:18
-
-
Save rust-play/9496a2ad72ff2bf15d275c8da3b87dcc to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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