找工作-结束进程数(python)
s1 = '3 1 5 21 10'
s2 = '0 3 3 1 5'
s3 = '3'
def numberTree(s1, s2, s3):
s1 = s1.split(' ')
s2 = s2.split(' ')
c = s3.split(' ')
count = 1
while True:
b = []
# 找父节点索引,父节点索引就是子节点索引
for index, nums in enumerate(s2):
if nums in c:
b.append(index)
# print(b)
# 若b为空,退出
if len(b) == 0:
break
# 找子节点,子节点就是下一个父节点
c = []
for index in b:
count += 1
c.append(s1[index])
# print(c)
return count
print(numberTree(s1, s2, s3))