Its working in my machine . but OJ is giving error for {1,#,2}


  • 0
    P
        class Solution {
    public:
    
        void flatten(TreeNode *root) 
        {
            static TreeNode *lastVisited = NULL;
            
          if(root == NULL)
            return;
    
        if(lastVisited != NULL) {
            lastVisited->left = root;
        }
        lastVisited = root;
    
        flatten(root->left);
        flatten(root->right);
            
        }
    };
    

    Please somebody help.


  • 0
    M

    I'm having the same issue (with different code, but the same input). Works fine on my machine.

    EDIT: Always setting the left node to null (even though it was already null) seems to have fixed it.... weird.


Log in to reply
 

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