Skip to content

Commit 7e4c4c8

Browse files
committed
Create: 0094-binary-tree-inorder-traversal.rs
1 parent ee7a3bc commit 7e4c4c8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::cell::RefCell;
2+
use std::rc::Rc;
3+
impl Solution {
4+
pub fn inorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {
5+
fn inorder(node: &Option<Rc<RefCell<TreeNode>>>, result: &mut Vec<i32>) {
6+
if let Some(v) = node {
7+
let v = v.borrow();
8+
inorder(&v.left, result);
9+
result.push(v.val);
10+
inorder(&v.right, result);
11+
}
12+
}
13+
14+
let mut result = vec![];
15+
if let Some(v) = root {
16+
inorder(&Some(v), &mut result);
17+
}
18+
result
19+
}
20+
}

0 commit comments

Comments
 (0)