/** # Given the following tree: a / | b c d / \ | e f g / / \ h i j depth of tree: 4 deepest nodes: [h, i, j] least common ancestor of [h, i, j]: b Given a tree, find the smallest subtree that contains all of the tree‘s deepest nodes. (ie, find the LCA of the deepest nodes) */ TreeNode { value: int, childern: List<TreeNode>, parent: TreeNode, } public TreeNode rootOfTheSmallestSubTreeForAllDeepestNodes(TreeNode root) { } TreeNode res = // nodes=[h, i, g], ancestor={h: e, i: f, j: f, etc} public TreeNode getLowestCommonAncestor(List<TreeNode> nodes) { int num = nodes.length(); Map<TreeNode, Integer> map = new HashMap<>(); for (TreeNode node : nodes) { pass(map, node, num); } } public void pass (Map<TreeNode, Integer> map, TreeNode node, int num) { } public void getDeepNodes (TreeNode root, int[] depth, int currDepth, Set<TreeNode> set) { if) }
用 map 记录深度