Skip to content

Commit af81b5b

Browse files
committed
solved: 226. Invert Binary Tree
Signed-off-by: rajput-hemant <[email protected]>
1 parent f39dbdc commit af81b5b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
// Definition for a binary tree node.
4+
type TreeNode struct {
5+
Val int
6+
Left *TreeNode
7+
Right *TreeNode
8+
}
9+
10+
func invertTree(root *TreeNode) *TreeNode {
11+
if root == nil {
12+
return nil
13+
}
14+
15+
invertTree(root.Left)
16+
invertTree(root.Right)
17+
18+
root.Left, root.Right = root.Right, root.Left
19+
20+
return root
21+
}

0 commit comments

Comments
 (0)