Share my simple 24ms c++ solution


  • 2
    C
    void connect(TreeLinkNode *root) {
        if (root == NULL) { return; }
    	TreeLinkNode* p = root;
    	TreeLinkNode* nextLevel = root->left;
    
    	while (p->left)
    	{
    		p->left->next = p->right;
    		if (p->next)
    		{
    			p->right->next = p->next->left;
    			p = p->next;
    		}
    		else
    		{
    			p = nextLevel;
    			nextLevel = p->left;
    		}
    	}
    }

Log in to reply
 

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