1 /** 2 * Definition of TreeNode: 3 * class TreeNode { 4 * public: 5 * int val; 6 * TreeNode *left, *right; 7 * TreeNode(int val) { 8 * this->val = val; 9 * this->left = this->right = NULL; 10 * } 11 * } 12 */ 13 14 //递归 15 class Solution { 16 public: 17 /* 18 * @param root: A Tree 19 * @return: Postorder in ArrayList which contains node values. 20 */ 21 22 void inorder(TreeNode *root, vector<int> &result) { 23 if (root->left != NULL) { 24 inorder(root->left, result); 25 } 26 if (root->right != NULL) { 27 inorder(root->right, result); 28 } 29 result.push_back(root->val); 30 } 31 32 vector<int> postorderTraversal(TreeNode * root) { 33 // write your code here 34 vector<int> result; 35 if (root == NULL) { 36 return result; 37 } 38 inorder(root, result); 39 return result; 40 } 41 };