Runtime error, can't find reason, beg for help!


  • 0
    L
        vector<vector<int> > levelOrder(TreeNode *root) {
        queue<TreeNode *> level;
        level.push(root);
        TreeNode *mark = new TreeNode(9);
        level.push(mark);
        vector<vector<int> > result;
        vector<int> currLevel;
    
        while(!level.empty())
        {
            TreeNode * curr = level.front();
            if(curr != mark)
            {
                 level.pop();
                 if(curr->left != nullptr)
                    level.push(curr->left);
                 if(curr->right != nullptr)
                    level.push(curr->right);
                 if(curr != nullptr)
                     currLevel.push_back(curr->val);
            }
            else{
                level.pop();
                level.push(curr);
                result.push_back(currLevel);
                currLevel.clear();
            }
        }
        return result;
    }

Log in to reply
 

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