Advertisement
Guest User

Untitled

a guest
May 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /// TreeNode
  2. #[derive(Debug, Eq)]
  3. pub struct TreeNode {
  4. pub val: i32,
  5. pub left: Option<Rc<RefCell<TreeNode>>>,
  6. pub right: Option<Rc<RefCell<TreeNode>>>,
  7. }
  8.  
  9. impl TreeNode {
  10. #[inline]
  11. pub fn new(val: i32) -> Self {
  12. TreeNode {
  13. val,
  14. left: None,
  15. right: None,
  16. }
  17. }
  18. }
  19.  
  20. impl PartialEq for TreeNode {
  21. fn eq(&self, other: &TreeNode) -> bool {
  22. if self.val != other.val {
  23. return false
  24. }
  25. let comparator = |a: &Option<Rc<RefCell<TreeNode>>>, b: &Option<Rc<RefCell<TreeNode>>>| -> bool {
  26. if *a == *b {
  27. return true;
  28. }
  29.  
  30. if *a == None || *b == None {
  31. return false;
  32.  
  33. }
  34.  
  35. a.as_ref().unwrap() == b.as_ref().unwrap()
  36. };
  37.  
  38. comparator(&self.left, &other.left) && comparator(&self.right, &other.right)
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement