Simple recursive accepted solution C++


  • 0
    I
    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            if (!root)
              return;
              
            TreeLinkNode * curr = root;
            if (curr->left) {
                curr->left->next = curr->right;
            }
            
            if (curr->next) {
                if (curr->right) 
                  curr->right->next = curr->next->left;
            }
            
            connect(curr->left);
            connect(curr->right);
        }
    };
    

Log in to reply
 

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