Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// TreeNode
- #[derive(Debug, Eq)]
- pub struct TreeNode {
- pub val: i32,
- pub left: Option<Rc<RefCell<TreeNode>>>,
- pub right: Option<Rc<RefCell<TreeNode>>>,
- }
- impl TreeNode {
- #[inline]
- pub fn new(val: i32) -> Self {
- TreeNode {
- val,
- left: None,
- right: None,
- }
- }
- }
- impl PartialEq for TreeNode {
- fn eq(&self, other: &TreeNode) -> bool {
- if self.val != other.val {
- return false
- }
- let comparator = |a: &Option<Rc<RefCell<TreeNode>>>, b: &Option<Rc<RefCell<TreeNode>>>| -> bool {
- if *a == *b {
- return true;
- }
- if *a == None || *b == None {
- return false;
- }
- a.as_ref().unwrap() == b.as_ref().unwrap()
- };
- comparator(&self.left, &other.left) && comparator(&self.right, &other.right)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement