My easy solution


  • 0
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            if(!root||!root->left) return;
            TreeLinkNode *current_left=root;//current layer's leftest node
            TreeLinkNode *current=current_left;
            while(current->left){
                current->left->next=current->right;
                current->right->next=current->next?current->next->left:NULL;
                current=current->next;
                if(!current){
                    current_left=current_left->left;
                    current=current_left;
                }   
            }    
        }
    };

  • 0
    W

    cool thing huh


Log in to reply
 

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