[LeetCode] Binary Tree Postorder Traversal dfs,深度搜索
一题后续遍历树的问题,很基础,统计哪里的4ms 怎么实现的。- -
#include <iostream> #include <vector> using namespace std; /** * Definition for binary tree */ struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; class Solution { public: vector<int> postorderTraversal(TreeNode *root) { vector<int> ret; if(root==NULL) return ret; help_f(root,ret); return ret; } void help_f(TreeNode *node,vector<int> &ret) { if(node==NULL) return; help_f(node->left,ret); help_f(node->right,ret); ret.push_back(node->val); } }; int main() { return 0; }