Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1d6ef1

Browse files
committed
GO: 226. Invert Binary Tree
1 parent 8a8654d commit d1d6ef1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

go/226-Invert-Binary-Tree.go

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

0 commit comments

Comments
 (0)