RunTime Error,which wrong


  • 0
    M

    /
    class Solution {
    public:
    vector<vector<int>> levelOrderBottom(TreeNode
    root) {
    vector <vector<TreeNode*>>midresult;
    vector<vector<int>>result;
    vector <TreeNode*>level;
    vector<int>mid;

        if(!root){ 
            level.push_back(root);
            midresult.push_back(level);
            for(int i=0;i<midresult.size();i++)
            {
               
                 level.clear();
                for(int j=0;j<midresult[i].size();j++)
                {
                   
                    if(!midresult[i][j]->left) level.push_back(root->left);
                    if(!midresult[i][j]->right)level.push_back(root->right);
                    
                        }
                        if(level.size()>0) midresult.push_back(level);
            }
           
            while(midresult.size()>0)
            {
                mid.clear();
            
            for(int i=0;i<midresult[midresult.size()-1].size();i++)
            {
                mid.push_back(midresult[midresult.size()-1][i]->val);
            }
            result.push_back(mid);
            midresult.pop_back();
            }
          
        }
       
       return result;
        
    }
    

    };


Log in to reply
 

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