摘要: class Solution(object): def __init__(self, root, node1, node2): self.root = root # 树的根结点 self.node1 = node1 self.node2 = node2 # 需要求的两个结点 @staticmethod def get... 阅读全文
posted @ 2018-10-30 14:38 findtruth123 阅读(199) 评论(0) 推荐(0) 编辑
摘要: from collections import deque def get_depth(tree): if not tree: return 0 if not tree.left and not tree.right: return 1 return 1 + max(get_depth(tree.left), get_depth(tre... 阅读全文
posted @ 2018-10-30 14:16 findtruth123 阅读(208) 评论(0) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): """ 非二叉搜索树,建树的... 阅读全文
posted @ 2018-10-30 13:52 findtruth123 阅读(512) 评论(0) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): def __init__(self)... 阅读全文
posted @ 2018-10-30 13:19 findtruth123 阅读(327) 评论(0) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): def __init__(self)... 阅读全文
posted @ 2018-10-30 11:13 findtruth123 阅读(183) 评论(0) 推荐(0) 编辑
摘要: def is_post_order(order): length = len(order) if length: root = order[-1] left = 0 while order[left] < root: left += 1 right = left while r... 阅读全文
posted @ 2018-10-30 10:55 findtruth123 阅读(170) 评论(0) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): def __init__(self)... 阅读全文
posted @ 2018-10-30 10:39 findtruth123 阅读(326) 评论(1) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): def __init__(self)... 阅读全文
posted @ 2018-10-30 10:12 findtruth123 阅读(295) 评论(0) 推荐(0) 编辑
摘要: from collections import deque class TreeNode(object): """ 二叉树结点定义 """ def __init__(self, x): self.val = x self.left = None self.right = None class Tree(obj... 阅读全文
posted @ 2018-10-30 09:28 findtruth123 阅读(242) 评论(0) 推荐(0) 编辑