题解 | #二叉树的后序遍历#
二叉树的后序遍历
http://www.nowcoder.com/practice/1291064f4d5d4bdeaefbf0dd47d78541
C++代码:
class Solution {
private:
vector<int> ans;
public:
vector<int> postorderTraversal(TreeNode* root) {
backTrack(root);
return ans;
}
void backTrack(TreeNode *root) {
if (root) {
backTrack(root->left);
backTrack(root->right);
ans.push_back(root->val);
}
}
};