HELP: What's wrong with my code?


  • 0
    K
    /**
     * Definition for binary tree with next pointer.
     * struct TreeLinkNode {
     *  int val;
     *  TreeLinkNode *left, *right, *next;
     *  TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
     * };
     */
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            if(root==NULL) return;
            TreeLinkNode *currentNode = root,*uperNode = root;
            currentNode->next = NULL;
            TreeLinkNode *MostLeftP = currentNode->left;
            while(MostLeftP!=NULL)
            {
            currentNode = MostLeftP;
            while(uperNode!=NULL)
            {
                currentNode->next = uperNode->right;
                currentNode = uperNode->right;
                uperNode = uperNode->next;
                if(uperNode!=NULL)
                {currentNode->next = uperNode->left;
                currentNode =uperNode->left;
                }
                else 
                {
                currentNode->next = NULL;
                uperNode = MostLeftP;}
            }
            MostLeftP = MostLeftP->left;
            
            
            }
        }
    };
    

    Submission Result: Runtime Error

    Last executed input: {1,2,3}


Log in to reply
 

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