Найти - Пользователи
Полная версия: Как определить максимальную глубину дерева?
Начало » Python для новичков » Как определить максимальную глубину дерева?
1
pasaranax
Дерево примерно такого вида:
class Tree():
def __init__(leaf=False):
self.childs = [] # где дети это тоже экземпляры Tree
self.leaf = leaf # является ли узел листом
o7412369815963
что-то типа такого:
def get_depth():
if not self.childs: return 1
return max(map(lambda x:x.get_child(),self.childs)) + 1
(код не тестировал)
pasaranax
спасибо, работает, хотя не совсем понимаю как )
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB