leetcode Binary Tree Postorder Traversal 的题目咨询

帘项小竹 帘项小竹 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
题目:
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) {}
* };
*/
// #include<vector>
class Solution {
public:
vector<int> postorderTraversal(TreeNode *root) {
vector<int> iter;
postorderTraversal(root->left);
postorderTraversal(root->right);
iter.push_back(root->val);

}
};
报错:Submission Result: Runtime Error

Last executed input: {}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部