3:解题代码:
/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
/**
* @param root: The root of binary tree.
* @return: Postorder in vector which contains node values.
*/
public:
std::vector<int> binary;
vector<int> postorderTraversal(TreeNode *root) {
// write your code here
if(root==NULL)return binary;
else
{
postorderTraversal(root->left);
postorderTraversal(root->right);
binary.push_back(root->val);
return binary;
}
}
};