12 line c solution.


  • 1
    A

    void connect(struct TreeLinkNode *root) {

    if(!root) return;
    struct TreeLinkNode * lr = root->left, * rl = root->right;
    while(lr) {
        lr->next =  rl;
        if (rl) {
            rl = rl->left;
        }
        lr = lr->right;
    }
    connect(root->left);
    connect(root->right);
    return;
    

    }


Log in to reply
 

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