---
# System prepended metadata

title: 'LeetCode #145 [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/)'
tags: [Recursion, LeetCode, Easy, Postorder, Tree]

---

###### tags: `LeetCode` `Recursion` `Postorder` `Tree` `Easy`
# LeetCode #145 [Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/)
### (Easy)
給定一個二元樹，返回它的後序遍歷。


---
與#94類似, 只不過postorder的拜訪順序為左子樹->右子樹->root。


---
```
class Solution {
public:
    vector<int> postorderTraversal(TreeNode* root) {
        if(root){
            vector<int> nodes;
            helper(root, nodes);
            return nodes;
        }
        return {};
    }
    void helper(TreeNode* root, vector<int>& nodes){
        if(root){
            helper(root->left, nodes);
            helper(root->right, nodes);
            nodes.push_back(root->val);
        }
    }
};
```