Share my 9ms C solution


  • 2

    more codes see:https://github.com/lightmen/leetcode.git

    void connect(struct TreeLinkNode *root) {

    struct TreeLinkNode *next_parent,*cursor;
    if(!root)
        return ;
    cursor = root;
    cursor->next = NULL;
    while(cursor){
        next_parent = cursor;
        while(next_parent){
            if(next_parent->left){
                next_parent->left->next = next_parent->right;
                next_parent->right->next = NULL;
            }
            if(next_parent->next && next_parent->right)
                next_parent->right->next = next_parent->next->left;
            next_parent = next_parent->next;
        }
        cursor = cursor->left;
    }
    

    }


Log in to reply
 

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