Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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> res;
rec(res, root);
return res;
}
void rec(vector<int> &res, TreeNode* root){
if(root == NULL) return;
rec(res, root->left);
rec(res, root->right);
res.push_back(root->val);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment