leetcode---binary-tree-postorder-traversal---树后续遍历
来源:互联网 发布:小米盒子网络连接不上 编辑:程序博客网 时间:2024/06/07 05:38
Given a binary tree, return the postorder traversal of its nodes’ values.
For example:
Given binary tree{1,#,2,3},
1
\
2
/
3
return[3,2,1].
Note: Recursive solution is trivial, could you do it iteratively?
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: void dfs(vector<int> &ans, TreeNode *root) { if(root) { if(root->left) { dfs(ans, root->left); } if(root->right) { dfs(ans, root->right); } ans.push_back(root->val); } return; } vector<int> postorderTraversal(TreeNode *root) { vector<int> ans; dfs(ans, root); return ans; }};
阅读全文
0 0
- Binary Tree Postorder Traversal 二叉树后续遍历@LeetCode
- leetcode 145. Binary Tree Postorder Traversal 二叉树后续遍历
- leetcode---binary-tree-postorder-traversal---树后续遍历
- 【二叉树的后续遍历】Binary Tree Postorder Traversal
- LeetCode 145 Binary Tree Postorder Traversal(二叉树的后续遍历)+(二叉树、迭代)
- leetcode 145. Binary Tree Postorder Traversal-后续遍历|递归|非递归
- leetcode---Binary Tree Inorder Traversal---后续遍历
- 145. Binary Tree Postorder Traversal 树后续遍历 flag方法和reverse方法
- [leetcode]Construct Binary Tree from Inorder and Postorder Traversal (利用中序遍历和后续遍历确定一颗二叉树)
- Leetcode 树 Binary Tree Postorder Traversal
- LeetCode Binary Tree Postorder Traversal
- LeetCode:Binary Tree Postorder Traversal
- Leetcode: Binary Tree Postorder Traversal
- Leetcode: Binary Tree Postorder Traversal
- LeetCode:Binary Tree Postorder Traversal
- Leetcode Binary Tree Postorder Traversal
- [LeetCode]Binary Tree Postorder Traversal
- [LeetCode] Binary Tree Postorder Traversal
- Codeforces Round #439 (Div. 2) 题解(869A,869B,869C,869E)
- 【图像处理】MATLAB:空间滤波
- leetcode 265. Paint House II
- 题目学习——一开始我是拒绝的
- Java实现读取pdf文件内容(how to read pdf in java)
- leetcode---binary-tree-postorder-traversal---树后续遍历
- C#工程的模块化实现
- 《Java基础与案例开发详解》(五)
- SQL注入之进阶篇
- 一分钟让你明白货币贬值现象
- 端口扫描
- 函数传值
- 线程池的理解
- 30天自制操作系统day2