leetcode_test_utils/tree/
raw_def.rs

1//! Original definition of binary tree in leetcode, on which all the algorithms
2//! and operations are performed.
3
4use std::cell::RefCell;
5use std::rc::Rc;
6
7/// Leetcode definition of binary tree structure.
8#[derive(Debug, PartialEq, Eq)]
9pub struct TreeNode {
10    pub val: i32,
11    pub left: Option<Rc<RefCell<TreeNode>>>,
12    pub right: Option<Rc<RefCell<TreeNode>>>,
13}
14
15impl TreeNode {
16    /// Create a new node with value `val` and left & right child [`None`].
17    #[inline]
18    pub fn new(val: i32) -> Self {
19        TreeNode {
20            val,
21            left: None,
22            right: None,
23        }
24    }
25}