catch-up
This commit is contained in:
25
invert-binary-tree/sol.go
Normal file
25
invert-binary-tree/sol.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition for a binary tree node.
|
||||
* type TreeNode struct {
|
||||
* Val int
|
||||
* Left *TreeNode
|
||||
* Right *TreeNode
|
||||
* }
|
||||
*/
|
||||
func invertTree(root *TreeNode) *TreeNode {
|
||||
if root == nil {
|
||||
return nil
|
||||
}
|
||||
root.Left, root.Right = root.Right, root.Left
|
||||
invertTree(root.Left)
|
||||
invertTree(root.Right)
|
||||
return root
|
||||
}
|
Reference in New Issue
Block a user