Question about Memory Limit Exceeded


  • 0
    V
    public TreeNode upsideDownBinaryTree(TreeNode root) {
    if (root==null) return null;
    TreeNode leftChild = root.left;
    TreeNode rightChild =root.right;
    while (leftChild!=null){
    
        TreeNode leftLeft = leftChild.left;
        TreeNode leftRight = leftChild.right;
        
        leftChild.left=rightChild;
        leftChild.right=root;
        
        root = leftChild;
        leftChild=leftLeft;
        rightChild=leftRight;
    }
    return root;
    

    }

    I don't understand why it will have Memory Limit Exceeded...can anyone help? Thanks!


Log in to reply
 

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