Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> postorderTraversal(TreeNode* root) {
- if(!root)return {};
- stack<TreeNode*>s1,s2;
- vector<int>v;
- s2.push(root);
- while(!s2.empty()){
- TreeNode*ll=s2.top();
- s2.pop();
- s1.push(ll);
- if(ll->left)s2.push(ll->left);
- if(ll->right)s2.push(ll->right);
- }
- while(!s1.empty()){
- v.push_back(s1.top()->val);
- s1.pop();
- }
- return v;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement