diff options
author | terminaldweller <thabogre@gmail.com> | 2023-02-18 04:01:24 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2023-02-18 04:01:24 +0000 |
commit | 49a72dcf24ba4f8d6b4f3beecc9e6d864fd8bb81 (patch) | |
tree | e696fcb6547cffee99630f0a551dd572ac585b2a /226/main.go | |
parent | 783 (diff) | |
download | leetcode-49a72dcf24ba4f8d6b4f3beecc9e6d864fd8bb81.tar.gz leetcode-49a72dcf24ba4f8d6b4f3beecc9e6d864fd8bb81.zip |
226
Diffstat (limited to '')
-rw-r--r-- | 226/main.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/226/main.go b/226/main.go new file mode 100644 index 0000000..da66748 --- /dev/null +++ b/226/main.go @@ -0,0 +1,42 @@ +package main + +import "fmt" + +type TreeNode struct { + Val int + Left *TreeNode + Right *TreeNode +} + +func invertTree(root *TreeNode) *TreeNode { + var invert func(root *TreeNode) + invert = func(root *TreeNode) { + if root == nil { + return + } + + root.Left, root.Right = root.Right, root.Left + invert(root.Left) + invert(root.Right) + } + invert(root) + + return root +} + +// func invertTree(root *TreeNode) *TreeNode { +// if root == nil { +// return nil +// } + +// right := invertTree(root.Right) +// left := invertTree(root.Left) +// root.Left = right +// root.Right = left + +// return root +// } + +func main() { + fmt.Println("vim-go") +} |