注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
刚面完就是一个类型的题,就是一个有方向的graph,ancestor啊children走来走去,其实都是bsf/dsf问到底,这是最后一题
"""
Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The data is formatted as a list of (parent, child) pairs, where each individual is assigned a unique integer identifier.
For example, in this diagram, the earliest ancestor of 6 is 14, and the earliest ancestor of 15dPairs2, 8) => 4
findEarliestAncestor(parentChildPairs2, 7) => 4
findEarliestAncestor(parentChildPairs2, 6) => 14
findEarliestAncestor(parentChildPairs2, 15) => 14
findEarliestAncestor(parentChildPairs2, 14) => null or -
"""
求大米!!!
|