Skip to content

Commit ebe067d

Browse files
committed
refactor Invert Binary Tree
1 parent 3c18bdd commit ebe067d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

go/invert_binary_tree.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
package main
33

44
func invertTreeRecursive(root *TreeNode) *TreeNode {
5-
if root != nil {
6-
root.Left, root.Right = invertTreeRecursive(root.Right), invertTreeRecursive(root.Left)
5+
if root == nil {
6+
return nil
77
}
8+
root.Left, root.Right = invertTreeRecursive(root.Right), invertTreeRecursive(root.Left)
89
return root
910
}
1011

0 commit comments

Comments
 (0)