Recursion C++


  • 0

    Simple C++

    class Solution {
    public:
        void connect(TreeLinkNode *root) {
            
            if (root == NULL) {
                return;
            }
            root->next = NULL;
            connectTwoTree(root->left, root->right);
        }
        
        void connectTwoTree(TreeLinkNode* tree1, TreeLinkNode* tree2) {
            if(tree1 == NULL && tree2 == NULL) {
                return;
            }
            
            tree1->next = tree2;
            
            connectTwoTree(tree1->left, tree1->right);
            connectTwoTree(tree2->left, tree2->right);
            connectTwoTree(tree1->right, tree2->left);
            
            
        }
    };
    

Log in to reply
 

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