Skip to content

Commit

Permalink
Create 0226-invert-binary-tree.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyue5 authored Nov 19, 2023
1 parent 394cd47 commit 08f9b44
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rust/0226-invert-binary-tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::rc::Rc;
use std::cell::RefCell;
impl Solution {
pub fn invert_tree(root: Option<Rc<RefCell<TreeNode>>>) -> Option<Rc<RefCell<TreeNode>>> {
root.map(|node| {
{
let mut node_ref = node.borrow_mut();
let left = node_ref.left.take();
let right = node_ref.right.take();
node_ref.right = Solution::invert_tree(left);
node_ref.left = Solution::invert_tree(right);
}
node
})
}
}

0 comments on commit 08f9b44

Please sign in to comment.