Why My Solution Is Error...


  • 0
    T
    class Solution {
    public:
    vector<vector<int>> levelOrder(TreeNode* root) {
    	static int iDeep = 0;
    	static std::vector<vector<int> > akResult;
    	if (!root) return akResult;
    	//std::cout<<"---"<<std::endl;
    	if (iDeep >= (int)akResult.size()) {
    		akResult.push_back((std::vector<int>)0);
    	}
    	//std::cout<<iDeep<<std::endl;
    	akResult[iDeep].push_back(root->val);
    	if (root->left) {
    		iDeep++;
    		levelOrder(root->left);
    		--iDeep;
    	}
    	if (root->right) {
    		iDeep++;
    		levelOrder(root->right);
    		--iDeep;
    	}
    	return akResult;
    }
    };

  • 0
    T

    I'm error at the test [1,2],my answer in Custom Testcase is [[1],[2]],,but,after my submit,the answer is [[1,1],[2]].


  • 0
    E

    i have the same error, but i don't know why


  • 0
    E

    i know why now
    don't use globle variable!!!!! and static variable!!!!!
    leetcode don't surport it


Log in to reply
 

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