H**********5 发帖数: 2012 | 1 lowest common ancestor with parent.
看了这行:
if(ancestor.containsKey(q)!=ancestor.isEmpty())
我第一遍是觉得晕的 |
H**********5 发帖数: 2012 | 2 whole code:
package Interview.PhoneInterview.LinkedIn.Tree.BTree.Recurse.
LowestCommonAncestor;
import java.util.HashMap;
import java.util.Map;
class BTreeNodeWithParent{
int val;
BTreeNodeWithParent left;
BTreeNodeWithParent right;
BTreeNodeWithParent parent;
BTreeNodeWithParent(int val){
this.val=val;
this.left=this.right=this.parent=null;
}
}
public class LowestCommonAncestorOfABinaryTreeWithParent {
BTreeNodeWithParent LCA(BTreeNodeWithParent p, BTreeNodeWithParent q)
{
// Creata a map to store ancestors of n1
Map ancestors = new HashMap<
BTreeNodeWithParent, Boolean>();
// Insert n1 and all its ancestors in map
while (p != null)
{
ancestors.put(q, Boolean.TRUE);
p = p.parent;
}
// Check if n2 or any of its ancestors is in
// map.
while (q != null)
{
if (ancestors.containsKey(q) != ancestors.isEmpty())
return q;
q = q.parent;
}
return null;
}
} |
A*******5 发帖数: 690 | 3 我还见过不会使用for 循环,五个同样的block,就是index不一样。还有号称有7年经
验的Web developer不知道在eclipse里新建JSP文件是选JSP Page还是JSP tag。。。当
然它可以说自己从来没用过eclipse |
H**********5 发帖数: 2012 | 4 这种傻逼烙印轻松的进去了,因为人烙印经理照。老中呢?lc刷的bug free 都难得进。
【在 A*******5 的大作中提到】 : 我还见过不会使用for 循环,五个同样的block,就是index不一样。还有号称有7年经 : 验的Web developer不知道在eclipse里新建JSP文件是选JSP Page还是JSP tag。。。当 : 然它可以说自己从来没用过eclipse
|