由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - [leetcode] Maximum Depth of Binary Tree
相关主题
请教大家一个问题:Maximum Height (Depth) of a Binary Tree Using PreOrder Traversal弱问:leetcode里Convert Sorted List to Binary Search Tree
[leetcode] Minimum Depth of Binary Tree 我的这个答案说wrong answer,但是我在本地跑就是对的.check if a binary tree is a valid binary search tree
讨论一道LeetCode题:Binary Tree Maximum Path SumBinary Tree Maximum Path Sum
Leetcode bst max path-----is this solution correct?Find the node with given value in binary tree in in-order
help: leetcode "Recover Binary Search Tree" -- 附代码leetcode Runtime error : Flatten Binary Tree to Linked List
Recover Binary Search Tree:以前的解法通不过了Flatten Binary Tree to Linked List的recursive解法
leetcode的OJ也会有错吗??请教一道Leetcode 题,多谢
为啥有两个case不对??Binary Tree Maximum Path SumLeetcode: Symmetric Tree有没有好的iterative的解法?
相关话题的讨论汇总
话题: treenode话题: null话题: prev话题: height话题: stack
进入JobHunting版参与讨论
1 (共1页)
t*******e
发帖数: 274
1
这题用dfs的iterative解法怎么做?如果有java code最好
s*******n
发帖数: 305
2
public int heightIterativeDFS() {
if (root==null) return 0;

Stack stack = new Stack();
stack.push(root);
int height=0;
TreeNode prev = null;

while(!stack.isEmpty()) {
TreeNode current=stack.peek();

if (prev==null || prev.left==current || prev.right==current) {
if (current.left!=null) stack.push(current.left);
else if (current.right!=null) stack.push(current.right);
}
else if (prev==current.left) {
if (current.right!=null) {
stack.push(current.right);
}
}
else {
stack.pop();
}
// System.out.println(stack.size());
prev=current;
if (height }
return height;
}
s*******n
发帖数: 305
1 (共1页)
进入JobHunting版参与讨论
相关主题
Leetcode: Symmetric Tree有没有好的iterative的解法?help: leetcode "Recover Binary Search Tree" -- 附代码
问一个leetcode上面binary tree的题目Recover Binary Search Tree:以前的解法通不过了
写了个symmetric tree的stack based iterative实现,有个bugleetcode的OJ也会有错吗??
大牛帮我看看这哪错了? iterative inorder traversal为啥有两个case不对??Binary Tree Maximum Path Sum
请教大家一个问题:Maximum Height (Depth) of a Binary Tree Using PreOrder Traversal弱问:leetcode里Convert Sorted List to Binary Search Tree
[leetcode] Minimum Depth of Binary Tree 我的这个答案说wrong answer,但是我在本地跑就是对的.check if a binary tree is a valid binary search tree
讨论一道LeetCode题:Binary Tree Maximum Path SumBinary Tree Maximum Path Sum
Leetcode bst max path-----is this solution correct?Find the node with given value in binary tree in in-order
相关话题的讨论汇总
话题: treenode话题: null话题: prev话题: height话题: stack