【发布时间】:2015-07-15 00:31:22
【问题描述】:
这是我解决这个问题的代码
def height(t):
"""Return the depth of the deepest node in the tree."""
if isinstance(t, list):
t = t[1:]
if t != empty:
return 1 + max([height(x) for x in t])
return 0
但它并没有像我预期的那样返回值。任何人都可以解决这个问题吗? 谢谢。 我的树方法是:
def tree(entry, subtrees=[]):
return lambda dispatch: entry if dispatch == 'entry' else list(subtrees)
def entry(tree):
return tree('entry')
def subtrees(tree):
return tree('subtrees')
【问题讨论】:
-
树形输入示例?
-
@heinst height(tree(1, [tree(2), tree(3)]))
-
因为你没有关闭评论,
标签: python algorithm list tree