由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Flatten Binary Tree to Linked List的recursive解法
相关主题
leetcode Runtime error : Flatten Binary Tree to Linked ListInterview question::
min depth binary tree用recursive解法一般能过关麽?为啥有两个case不对??Binary Tree Maximum Path Sum
问一个题目贴个自己的答案:Binary Tree Max Path Sum
帮我看一下5行代码check if a binary tree is a valid binary search tree
关于leetcode上的一道题再问个C++的基础问题(in order traversal)
查找binary tree中有多少个uni-valued subtree判断是不是binary search tree-leetcode
[leetcode] Maximum Depth of Binary Treehelp: leetcode "Recover Binary Search Tree" -- 附代码
问一道google面经Find the node with given value in binary tree in in-order
相关话题的讨论汇总
话题: root话题: treenode话题: helper话题: null话题: flatten
进入JobHunting版参与讨论
1 (共1页)
a***e
发帖数: 413
1
这道题的iterative解法比较好懂,但看到下面这个recursive的就觉得想不清楚了。一
直对树的recursion挺糊涂的。怎么才能搞清楚呢?多谢!
class Solution {
public:
void flatten(TreeNode *root) {
helper(root, NULL);
}

TreeNode *helper(TreeNode *root, TreeNode *tail){
if (NULL==root) return tail;

root->right = helper(root->left, helper(root->right, tail));
root->left = NULL;
return root;
}
};
m*****k
发帖数: 731
2
http://www.programcreek.com/2013/01/leetcode-flatten-binary-tre
while condition 的 stack empty check 貌似是多余的,各位觉得呢?
a***e
发帖数: 413
3
这个是iterative的解法 , 不用stack可以更简洁
1 (共1页)
进入JobHunting版参与讨论
相关主题
Find the node with given value in binary tree in in-order关于leetcode上的一道题
有没有人同觉得Recover Binary Search Tree的solution using O(n) space并不是那么straight forward么?查找binary tree中有多少个uni-valued subtree
leetcode交了钱的能share一下题么?[leetcode] Maximum Depth of Binary Tree
请教一道g算法题问一道google面经
leetcode Runtime error : Flatten Binary Tree to Linked ListInterview question::
min depth binary tree用recursive解法一般能过关麽?为啥有两个case不对??Binary Tree Maximum Path Sum
问一个题目贴个自己的答案:Binary Tree Max Path Sum
帮我看一下5行代码check if a binary tree is a valid binary search tree
相关话题的讨论汇总
话题: root话题: treenode话题: helper话题: null话题: flatten