Skip to content

Commit

Permalink
Time: 6 ms (23.11%), Space: 8.5 MB (22.63%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Jul 22, 2023
1 parent 99ea637 commit 29a7b1d
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
vector<int> ans;
void solve(TreeNode* root)
{
if(root==NULL)return;
solve(root->left);
solve(root->right);
ans.push_back(root->val);
}
vector<int> postorderTraversal(TreeNode* root) {
solve(root);
return ans;


}
};

0 comments on commit 29a7b1d

Please sign in to comment.