题目名称:皇位继承顺序
难度:中等
题目描述:
示例输入:["ThroneInheritance","birth","birth","birth","birth","birth","birth","getInheritanceOrder","death","getInheritanceOrder"][["king"],["king","andy"],["king","bob"],["king","catherine"],["andy","matthew"],["bob","alex"],["bob","asha"],[null],["bob"],[null]]输出:[null,null,null,null,null,null,null,["king","andy","matthew","bob","alex","asha","catherine"],null,["king","andy","matthew","alex","asha","catherine"]]解释:ThroneInheritancet=newThroneInheritance("king");//继承顺序:kingt.birth("king","andy");//继承顺序:kingandyt.birth("king","bob");//继承顺序:kingandybobt.birth("king","catherine");//继承顺序:kingandybobcatherinet.birth("andy","matthew");//继承顺序:kingandymatthewbobcatherinet.birth("bob","alex");//继承顺序:kingandymatthewbobalexcatherinet.birth("bob","asha");//继承顺序:kingandymatthewbobalexashacatherinet.getInheritanceOrder();//返回["king","andy","matthew","bob","alex","asha","catherine"]t.death("bob");//继承顺序:kingandymatthewbob(已经去世)alexashacatherinet.getInheritanceOrder();//返回["king","andy","matthew","alex","asha","catherine"]提示:1=kingName.length,parentName.length,childName.length,name.length=15kingName,parentName,childName和name仅包含小写英文字母。所有的参数childName和kingName互不相同。所有death函数中的死亡名字name要么是国王,要么是已经出生了的人员名字。每次调用birth(parentName,childName)时,测试用例都保证parentName对应的人员是活着的。最多调用10^5次birth和death。最多调用10次getInheritanceOrder。来源:力扣(LeetCode)链接: