Skip to content

Commit

Permalink
226
Browse files Browse the repository at this point in the history
  • Loading branch information
TedTran2019 committed Jul 8, 2022
1 parent ca97a48 commit e895144
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ruby/226-Invert-Binary-Tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def invert_tree(root)
return root if root.nil?
return root if root.left.nil? && root.right.nil?

root.left, root.right = root.right, root.left
invert_tree(root.left)
invert_tree(root.right)
root
end

0 comments on commit e895144

Please sign in to comment.