leetcode Binary Tree Postorder Traversal 的题目咨询
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: {}
相关推荐
145.Binary Tree Postorder Traversal二叉树的后序遍历【LeetCode单题讲解系列】
145.Binary_Tree_Postorder_Traversal二叉树的后序遍历【LeetCode单题讲解系列】
python-leetcode题解之145-Binary-Tree-Postorder-Traversal
python python_leetcode题解之145_Binary_Tree_Postorder_Traversal
js-leetcode题解之145-binary-tree-postorder-traversal.js
javascript js_leetcode题解之145-binary-tree-postorder-traversal.js
leetcode-tree
二叉树的遍历 前中后序,递归和非递归算法 非递归算法:用stack辅助,出栈时机不一样,相当于深搜。 144-Binary Tree Preorder Traversal 94-Binary Tree Inorder Traversal 145-Binary Tree Postorder Traversal(后续的非递归时间不够可以先跳过,有点难) 层次遍历,队列辅助,相当于广搜。 102-Binary Tree Level Order Traversal 199-Binary Tree Right Side View:层次遍历的一个运用 树的构造 给出前中后序的序列中的两个,构造一棵树。递归。 前序 parent left-child right-child 中序 left-child parent right-child 后续 left-child right-child parent
LeetCode-js:用 JavaScript 解决 LeetCode 问题
LeetCode-js 用 JavaScript 解决 LeetCode 问题


其它技术问题
