With a single temp Node


  • 0
    P
    public TreeNode invertTree(TreeNode root) {
            
            if(root == null)
            {
                return null;
            }
            
            TreeNode tempLeft = invertTree(root.right);
            root.right = invertTree(root.left);
            root.left = tempLeft;
            
            return root;
        }
    

Log in to reply
 

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