首页 > 代码库 > LeetCode - Binary Tree Postorder Traversal

LeetCode - Binary Tree Postorder Traversal

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
   
    vector<int>fc;
    void dfs(TreeNode* fe){
        if(fe==NULL)return ;
            dfs(fe->left);
            dfs(fe->right);
        fc.push_back(fe->val);
    }
   
    vector<int> postorderTraversal(TreeNode* root) {
        dfs(root);
        return fc;
    }
};

LeetCode - Binary Tree Postorder Traversal