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;
    	}
    };
    

Log in to reply
 

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