Simple 16ms recursive C++ solution


  • 1
    S
    void connect(TreeLinkNode *root, TreeLinkNode* next) {
        root->next=next;
        if (root->left) {
            connect(root->left, root->right);
            connect(root->right, next?next->left:nullptr);
        }
    }
    void connect(TreeLinkNode *root) {
        if (root) {
            connect(root, nullptr);
        }
    }

  • 0
    L

    Thank you for sharing your sln, it's beautiful!


Log in to reply
 

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