Home Forums US Life tree 의 높이 구하는 알고리듬…이해가… tree 의 높이 구하는 알고리듬…이해가… Name * Password * Email deque 대신에 그냥 일반 stack으로 풀어도 결국 값은 동일합니다. 진행 순서만 다를뿐 결국 Leaf 노드까지 모두 가게 되는건 같으니까요. ` def tree_height(root) { stack = ([(root, 1)]) # (node, height) as tuple treeHeight = 0 while len(stack) > 0: node, height = stack.pop() # pop the last item treeHeight = max(treeHeight , height) # update the treeHeight if node.left: stack.append((node.left, height+1)) if node.right: stack.append((node.right, height+1)) return treeHeight } ` I agree to the terms of service Comment