Why my C++ code got a strange Compile Error


  • 0
    Z

    My code has 32 lines. The submission result is : Line 39: ‘class Solution’ has no member named 'levelOrderBottom’. Thx for anyone who knows why.

     class Solution {
    public:
    	vector<vector<int> > levelOrder(TreeNode *root) {
    		vector<vector<int> > ans;
    
    		if (root == NULL)	return ans;
    		vector<TreeNode *> temp(1,root);
    		while (!temp.empty() )
    		{
    			vector<int> row;
    			int len = temp.size();
    			row.resize(len );
    			for (int i = 0; i < len; i++)
    			{
    				row[i] = temp[i]->val;
    			}
    			ans.push_back(row);
    			for (int i = 0; i < len; i++)
    			{
    				if (temp[i]->left != NULL)	temp.push_back(temp[i]->left);
    				if (temp[i]->right != NULL)	temp.push_back(temp[i]->right);				
    			}
    			for (int i = 0; i < len; i++)
    			{
    				temp.erase(temp.begin());
    			}
    
    		}
    
    		vector<vector<int> > reverse_ans(ans.rbegin(),ans.rend());
    		return reverse_ans;
    	}
    };

  • 2
    Y

    Just change the 3rd line "levelOrder" to original function name "levelOrderBottom", Accepted

    class Solution {
    public:
    vector<vector<int> > levelOrder(TreeNode *root) {


  • 0
    Z

    Thanks. I get it.


Log in to reply
 

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