/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
//实现二叉树的递归遍历
class Solution {
public:
vector<int> ans;
vector<int> postorderTraversal(TreeNode *root) {
if(root == NULL) return ans;
postorder(root);
return ans;
}
void postorder(TreeNode *root)
{
//二叉树的访问顺序
if(root != NULL)
{
postorder(root->left);
postorder(root->right);
ans.push_back(root->val); //处理
}
}
};