/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> postorderTraversal(TreeNode* root) {
vector<int> v;
postOrder(root, v);
return v;
}
private:
void postOrder(TreeNode* root, vector<int>& v) {
if(!root) {
return;
}
postOrder(root->left, v);
postOrder(root->right, v);
v.push_back(root->val);
}
};