Why the solution shows"runtime error Last executed input: {1,#,2}" but run on my IDE is ok


  • 2
    TreeNode* function(TreeNode *node)
    {
    	if(node == NULL)
    		return NULL;
    	if(node->left == NULL && node->right == NULL)
    		return node;
    	if(node->left == NULL)
    		return function(node->right);
    	TreeNode *lastRight = node->right;
    	node->right = node->left;
    	TreeNode *l = function(node->left);
    	if(l != NULL)
    		l->right = lastRight;
    	TreeNode *r = function(lastRight);
    	return r;
    }
    void flatten(TreeNode *root) {
        function(root);
    }

  • 0
    W

    I think you forget to set left pointer to NULL.


  • 0

    Thank you very much!


Log in to reply
 

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