f*i
2 楼
Iterative inorder, when meet a leaf node, such node together with the nodes
in the stack form a path.
Time O(n)
space O(lgn)
in the stack form a path.
Time O(n)
space O(lgn)
c*t
5 楼
似乎可行,写了个recursion。等牛人写个iteration吧
public LinkedList longestPath(Node root) {
if (root == null)
return new LinkedList();
LinkedList leftPath = longestPath(root.left);
LinkedList rightPath = longestPath(root.right);
if (leftPath.size() >= rightPath.size()) {
leftPath.push(root);
return leftPath;
} else {
rightPath.push(root);
return rightPath;
}
}
【在 c********t 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: how about using post-order? for each node, discard shorter children path,
: save the longer one.
: time: O(n)
: space: O(length of longest path)
:
: nodes
public LinkedList
if (root == null)
return new LinkedList
LinkedList
LinkedList
if (leftPath.size() >= rightPath.size()) {
leftPath.push(root);
return leftPath;
} else {
rightPath.push(root);
return rightPath;
}
}
【在 c********t 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: how about using post-order? for each node, discard shorter children path,
: save the longer one.
: time: O(n)
: space: O(length of longest path)
:
: nodes
c*a
6 楼
150里面有一题很相近的啊
相关阅读
真是地狱般的两周关于H4的问题H1B transfer PP, 一个星期了还没有拿到receipt 正常吗?h1b的check. pay to写的是谁啊?是不是只有抽中Sevis Record才会显示 Change of Status Pending?OPT马上过期,H1B刚抽到,有必要延期OPT吗h1b两周了还是没声音今天在公司遭遇小型种族歧视事件,请支招。interview自我感觉和结果区别一个分支话题:有了H1b receipt 可以去延期驾照吗?h1b收到recipt就代表抽中了吗?只是还在处理中leetcode usage大拿们帮着填个关于FLG的工资表给bubblebubble发个道歉贴杳无音信的一天又要结束鸟opt已经过期,如果H1-B也没中,是不是就黑了opt 是累积算的?Amazon onsite 后, 多少时间出结果阿?问各位大大一个问题 顺便报了个approvequalcomm vs. nvidia?