Dedicated to mxcl, Creator of brew
:)
Problem Link: https://leetcode.com/problems/invert-binary-tree/
Solution:
/**
* 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
}
var temp = root.Left
root.Left = root.Right
root.Right = temp
invertTree(root.Left)
invertTree(root.Right)
return root
}
Top comments (0)