sharing my simple to understand C++ solution


  • 0
    A
    void connect(TreeLinkNode *left, TreeLinkNode *right) 
        {
        	if(left!=NULL)
        	{
        		left->next = right;
        		connect(left->left, left->right);
        		connect(left->right, right->left);
        		connect(right->left, right->right);
        	}
        }
        void connect(TreeLinkNode *root) {
            if(root!=NULL)
            connect(root->left, root->right); 
        }
    

Log in to reply
 

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