File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Definition for a binary tree node.
2
+ // #[derive(Debug, PartialEq, 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
+ use std:: rc:: Rc ;
20
+ use std:: cell:: RefCell ;
21
+ impl Solution {
22
+ pub fn invert_tree ( root : Option < Rc < RefCell < TreeNode > > > ) -> Option < Rc < RefCell < TreeNode > > > {
23
+ if let Some ( u) = & root {
24
+ let mut u = u. borrow_mut ( ) ;
25
+ let v = u. left . clone ( ) ;
26
+ u. left = Self :: invert_tree ( u. right . clone ( ) ) ;
27
+ u. right = Self :: invert_tree ( v) ;
28
+ }
29
+ root
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments