Advertisement
vaibhav1906

postorder

Jan 4th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3.    
  4.     void postorder(TreeNode * root, vector<int> &ans){
  5.         if(root==NULL)return;
  6.        
  7.         postorder(root->left,ans);
  8.         postorder(root->right,ans);
  9.         ans.push_back(root->val);
  10.        
  11.         return;
  12.        
  13.     }
  14.    
  15.     vector<int> postorderTraversal(TreeNode* root) {
  16.          vector<int> ans;
  17.         postorder(root, ans);
  18.        
  19.         return ans;
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement