C++ easy solution


  • 1

    class Solution {

    public:

    void connect(TreeLinkNode *root) {
        if (root && root->left) {
            root->left->next = root->right;
            TreeLinkNode *temp;
            temp = root->left;
            while (temp->right) {
                temp->right->next = temp->next->left;
                temp = temp->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.