标签:eve cto val stack treenode div tree turn color
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution 11 { 12 vector<int> res; 13 public: 14 vector<int> postorderTraversal(TreeNode* root) 15 { 16 if(!root) return res; 17 stack<TreeNode*> s; 18 s.push(root); 19 while(!s.empty()) 20 { 21 root = s.top(); 22 s.pop(); 23 res.push_back(root->val); 24 if(root->left) s.push(root->left); 25 if(root->right) s.push(root->right); 26 } 27 reverse(res.begin(),res.end()); 28 return res; 29 } 30 };
标签:eve cto val stack treenode div tree turn color
原文地址:https://www.cnblogs.com/yuhong1103/p/12622361.html