# 145. Binary Tree Postorder Traversal

## 1.問題

* 給予一個binary tree, 回傳post-order traversal得到的值

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LIKjtg4tW4NvSsZ9Blm%2F-LIKmS9GVeTWRKwYpLoV%2F2018072609.jpg?alt=media\&token=2e2ebfd4-d16c-4734-bf11-a41f2739fcb3)

## 2.想法

* post order traversal

## 3.程式碼

```
/**
 * 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);
    }
};
```

## 4.Performance

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LIKjtg4tW4NvSsZ9Blm%2F-LIKmb8eWs65b1hlWH4P%2F2018072610.jpg?alt=media\&token=e8395d4e-a33e-4692-bca3-f347d4ed61d2)
