Accepted but C++ code WRONG (missing return value)


  • 2
    T
    class Solution {
    public:
        vector<vector<int>> levelOrder(TreeNode* root) {
            vector<vector<int>> vvec;
            vector<int> vec;
            queue<TreeNode*> q;
            TreeNode *endoflevel = new TreeNode(0);
            if (root == NULL)
                return vvec;
            q.push(root); q.push(endoflevel);
            while(!q.empty()) {
                TreeNode *t;
                t = q.front(); q.pop();
                if (t == endoflevel) {
                    vvec.push_back(vec);
                    vec.clear();
                    if (!q.empty())
                        q.push(endoflevel);
                    continue;
                }
                vec.push_back(t->val);
                if (t->left) q.push(t->left);
                if (t->right) q.push(t->right);
            }
        // return vvec;
        }
    };
    

    I noticed missing the comment code once I clicked the "commit" button, what surprised me is that the OJ accepted it.


Log in to reply
 

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