Leetcoder: lowest common in multi-branch tree
给一个Employee类,有一个String name和一个List<Employee> directReport来表示一个公司的组织结构,然后给定一个公司的ceo和两个员工的名字,找到这两个员工的第一个common manager,给的两个员工一定存在。N-try tree的first common ancestor。楼主就用最naive的方法先找到从根到target节点的path然后在两个path中找第一个common ancestor。在电脑上写代码和测试样例,改掉测试样例的一个小bug之后通过。要求优化,说了用postorder traversal的方法来找,这样只需要遍历树一遍,说了一下整体的过程没有coding。Read full article from Leetcoder: lowest common in multi-branch tree
No comments:
Post a Comment