← 返回 snowflake 的题目列表Calculate New Tree Height After Node Deletion
类型:online_judge
Given a tree and a list of nodes, find the height of the tree after deleting the given nodes.
Input:
Representation of the tree (e.g., parent to children dictionary)
List of nodes to delete
Output:
Height of the tree after node deletions
Assume: All nodes in the deletion list are in the tree and the number of tree nodes does not exceed 1000.
Example 1:
Input: Tree = {1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, Delete node list = [3] Output: 3
Example 2:
Input: Tree = {1: [3], 3: [2], 2: []}, Delete node list = [2] Output: 2
Example 3:
Input: Tree = {1: [2], 2: [3], 3: [4], 4: []}, Delete node list = [2, 3] Output: 1
Example
Input
{1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []} 3