C++ recursive solution


  • 0
        void connect(TreeLinkNode *root) {
            if(!root) return;
            if(root->left){
                root->left->next = root->right;
                root->right->next = root->next? root->next->left : NULL;
            }
            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.