Skip to content

Commit ffc0de7

Browse files
committed
invert_binary_tree
1 parent 4945e38 commit ffc0de7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
182182
#### [223. Rectangle Area](https://github.com/hitzzc/go-leetcode/tree/master/rectangle_area)
183183
#### [224. Basic Calculator](https://github.com/hitzzc/go-leetcode/tree/master/basic_calculator)
184184
#### [225. Implement Stack using Queues](https://github.com/hitzzc/go-leetcode/tree/master/implement_stack_using_queues)
185+
#### [226. Invert Binary Tree](https://github.com/hitzzc/go-leetcode/tree/master/invert_binary_tree)
185186

186187

187188

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package invert_binary_tree
2+
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 nil
12+
}
13+
root.Left, root.Right = root.Right, root.Left
14+
invertTree(root.Right)
15+
invertTree(root.Left)
16+
return root
17+
}

0 commit comments

Comments
 (0)