Solution in Golang


  • 0
    J
    type TreeNode struct {
    	Val   int
    	Left  *TreeNode
    	Right *TreeNode
    }
    
    func invertTree(root *TreeNode) *TreeNode {
    	if root == nil {
    		return root
    	}
    	left := root.Left
    	root.Left = invertTree(root.Right)
    	root.Right = invertTree(left)
    	return root
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.