C++ easy understanding solution


  • 1
    A
    class Solution {
    public:
    void connect(TreeLinkNode *root) {
        if(!root) return ;
        TreeLinkNode *p = root;
        while(p->left ){
            p->left->next = p->right;
            TreeLinkNode *q = p;
            while(q->next){
                q->right->next = q->next->left;
                q->next->left->next = q->next->right;
                q = q->next;
            }
            p = p->left;
        }
    }
    };

Log in to reply
 

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