LeetCode145. Binary Tree Postorder Traversal(hard)
来源:互联网 发布:poe交换机端口不供电 编辑:程序博客网 时间:2024/06/06 11:43
原题地址:https://leetcode.com/problems/binary-tree-postorder-traversal/description/
题目:
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].
题解:
单纯的后序遍历,只需再写一个函数进行按后序遍历顺序递归即可
/** * 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: void post(TreeNode* root, vector<int>& pt) { if (root != nullptr) { post(root->left, pt); post(root->right, pt); pt.push_back(root->val); } } vector<int> postorderTraversal(TreeNode* root) { vector<int> pt; post(root, pt); return pt; }};
67 / 67 test cases passed.
Status: Accepted
Runtime: 3 ms
阅读全文
0 0
- LeetCode145. Binary Tree Postorder Traversal(hard)
- Binary Tree Postorder Traversal leetcode145
- LeetCode145:Binary Tree Postorder Traversal
- LeetCode145-Binary-Tree-Postorder-Traversal
- LeetCode145. Binary Tree Postorder Traversal
- leetcode145. Binary Tree Postorder Traversal
- LeetCode145—Binary Tree Postorder Traversal
- Leetcode145——Binary Tree Postorder Traversal
- Leetcode145: Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode145——Binary Tree Postorder Traversal二叉树后序遍历
- LeetCode145 Binary Tree Postorder Traversal(迭代实现) Java
- [Leetcode 145, Hard] Binary Tree Postorder Traversal
- [hard]145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal[hard]
- LeetCode #145 - Binary Tree Postorder Traversal - Hard
- LeetCode145 Binary Tree Postorder Traversal Java题解(递归 迭代)
- Hard-题目4:145. Binary Tree Postorder Traversal
- Leetcode 145. Binary Tree Postorder Traversal (Hard) (cpp)
- 那些年,Github上的干货!
- 笔试题:2017.9.10爱奇艺校招编程题【平方串】解题思路
- 北京可用DNS收集整理和速度评测
- JS——DOM表格
- Python通过MD5值实现重复文件的检测
- LeetCode145. Binary Tree Postorder Traversal(hard)
- 找出字符串中的最长连续数字子串
- 更新Windows 10 之后Kali引导丢失问题修复
- java程序路径通配符表达式合辑
- 10分钟看懂HTTPS
- 394. Decode String
- keras实验1Keras框架搭建
- Window下Tensorflow环境配置及Keras环境配置(包括各种报错解决方法)
- UML类图的6种关系