Reverse Level Order Time : Space : 12345678910111213141516171819202122232425262728/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */void dfs(TreeNode* node, vector<vector<int>>& seq, int dep) { if(!node) return; if(seq.size() == dep) seq.emplace_back(); seq[dep].push_back(node->val); dfs(node->left, seq, dep + 1); dfs(node->right, seq, dep + 1);}vector<int> Solution::solve(TreeNode* A) { vector<vector<int>> seq; dfs(A,seq,0); vector<int> res; for(int i = seq.size() - 1; i >= 0; i--) { for(int j = 0; j < seq[i].size(); j++) { res.push_back(seq[i][j]); } } return res;}