Easy to understand c++


  • 0
    N
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            if(!root) return;
            
            TreeLinkNode * leftmost = root, * curr = NULL;
            
            while(leftmost->left){
                curr = leftmost;
                while(curr){
                    curr->left->next = curr->right;
                    if(curr->next) curr->right->next = curr->next->left;
                    curr = curr->next;
                }
                leftmost = leftmost->left;
            }
            
            
        }
    };

Log in to reply
 

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