Input {0},my code have a problem,runtime error.Is there someone can tell me the reason?


  • 0
    S

    class Solution {
    public:
    void connect(TreeLinkNode *root) {
    vector<TreeLinkNode * > a,b;
    int i,j;
    if(root == NULL)
    return;
    a.push_back(root);
    root->next = NULL;
    while(1)
    {
    for(i = 0;i < a.size();i++)
    {
    if(a[i]->left != NULL)
    b.push_back(a[i]->left);
    if(a[i]->right != NULL)
    b.push_back(a[i]->right);
    for(j = 0;j < b.size() - 1;j++)
    b[j]->next = b[j + 1];
    if(b.size() > 0)
    b[j]->next = NULL;
    a.clear();
    a = b;
    b.clear();
    }
    if(a.empty())
    break;
    }

    }
    

    };


Log in to reply
 

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