Simple java 6-lines recursive code


  • 0
    P
        if (root == null){
            return null;
        }
        
        TreeNode newNode = new TreeNode(root.val);
        
        newNode.left = invertTree(root.right);
        newNode.right = invertTree(root.left);
        
        return newNode;

Log in to reply
 

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