Why this Solution is Wrong?


  • 0
    0
    1. class Solution { public:
      void connect(TreeLinkNode root)
      {
      if (!root) return;
      TreeLinkNode
      node1 = root->left;
      TreeLinkNode* node2 = root->right;
      while (node1 && node2)
      {
      node1->next = node2;
      if (node1->right) node1 = node1->right;
      else node1= node1->left;

              if (node2->left) node2 = node2->left;
              else node2 = node2->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.