Binary Tree Postorder Traversal
/** * 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> res; void dfs(TreeNode *root){ if(!root) return; dfs(root->left); dfs(root->right); res.push_back(root->val); } vector<int> postorderTraversal(TreeNode *root) { dfs(root); return res; } };