All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0001_0100.s0094_binary_tree_inorder_traversal.Solution.rs Maven / Gradle / Ivy

The newest version!
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search #Tree #Binary_Tree
// #Stack #Data_Structure_I_Day_10_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
// #2024_09_08_Time_0_ms_(100.00%)_Space_2.2_MB_(33.33%)

// Definition for a binary tree node.
// #[derive(Debug, PartialEq, Eq)]
// pub struct TreeNode {
//   pub val: i32,
//   pub left: Option>>,
//   pub right: Option>>,
// }
// 
// impl TreeNode {
//   #[inline]
//   pub fn new(val: i32) -> Self {
//     TreeNode {
//       val,
//       left: None,
//       right: None
//     }
//   }
// }
use std::rc::Rc;
use std::cell::RefCell;
impl Solution {
    pub fn inorder_traversal(root: Option>>) -> Vec {
       root.map(|root| {
                let n = root.borrow();
                let mut result = Self::inorder_traversal(n.left.clone());
                result.push(n.val);
                result.extend(Self::inorder_traversal(n.right.clone()));
                result
            })
            .unwrap_or_default() 
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy