Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1971 from AkifhanIlgaz/0094
Browse files Browse the repository at this point in the history
Create: 0094-binary-tree-inorder-traversal.rs
  • Loading branch information
tahsintunan authored Jan 9, 2023
2 parents d25bff8 + 7e4c4c8 commit 53778be
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rust/0094-binary-tree-inorder-traversal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::cell::RefCell;
use std::rc::Rc;
impl Solution {
pub fn inorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
fn inorder(node: &Option<Rc<RefCell<TreeNode>>>, result: &mut Vec<i32>) {
if let Some(v) = node {
let v = v.borrow();
inorder(&v.left, result);
result.push(v.val);
inorder(&v.right, result);
}
}

let mut result = vec![];
if let Some(v) = root {
inorder(&Some(v), &mut result);
}
result
}
}

0 comments on commit 53778be

Please sign in to comment.