Simple C# solution with recursion


  • 0
    N
    public TreeNode InvertTree(TreeNode root) 
        {
            if(root == null)
                return root;
            TreeNode temp = root.right;
            root.right = root.left;
            root.left = temp;
            InvertTree(root.left);
            InvertTree(root.right);
            return root;
        }
    

Log in to reply
 

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