Simple C++ code


  • 2
    L
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            if ( root && root->left )
            {
                root->left->next = root->right;
                connect (root->left);
                root->right->next = (root->next) ? (root->next->left) : (NULL);
                connect (root->right);
            }
        }
    };

  • 0
    S

    it is recursive, the space complexity may not fit


Log in to reply
 

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