题目链接:click~
/*题意:将二叉树中的结点一层一层的逆序输出*/
/**
*思路:在102那道题的代码上,直接将vector反转即可
*
*/
class Solution {
public:
void DFS(TreeNode *T, int level, vector<vector<int>> &path) {
if(T == NULL) return;
if(level == path.size()) {
path.resize(level+1);
}
path[level].push_back(T->val);
DFS(T->left, level+1, path);
DFS(T->right, level+1, path);
}
vector<vector<int> > levelOrderBottom(TreeNode *root) {
vector<vector<int>> path;
if(root == NULL) return path;
DFS(root, 0, path);
reverse(path.begin(), path.end());//反转
}
};