Simple C++ recursive solution


  • 0
    A
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
             if (root==NULL)
                return;
            if (root->left==NULL)//no more children
                return;
            if (root->next!=NULL){
                root->right->next=root->next->left;
            }
            root->left->next=root->right;
            connect(root->left);
            connect(root->right);
        }
    };
    

Log in to reply
 

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