Easy dfs recursive C++


#1
    vector<vector<int>>ans;
    void dfs(TreeNode* A,int h=0){
        if(A==NULL)return;
        if(ans.size()==h)ans.resize(h+1);
        ans[h].push_back(A->val);
        dfs(A->left,h+1);
        dfs(A->right,h+1);
    }
    vector<vector<int> > Solution::levelOrder(TreeNode* A) {
        ans.clear();dfs(A);return ans;
    }