Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created January 21, 2019 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/e7c481653fa1083d2f1f011b63fd4f99 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/e7c481653fa1083d2f1f011b63fd4f99 to your computer and use it in GitHub Desktop.
/**
* 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