摘要:
class Solution(object): def __init__(self, root, node1, node2): self.root = root # 树的根结点 self.node1 = node1 self.node2 = node2 # 需要求的两个结点 @staticmethod def get... 阅读全文
摘要:
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... 阅读全文
摘要:
from collections import deque class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Tree(object): """ 非二叉搜索树,建树的... 阅读全文
摘要:
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)... 阅读全文
摘要:
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)... 阅读全文
摘要:
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... 阅读全文
摘要:
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)... 阅读全文
摘要:
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)... 阅读全文
摘要:
from collections import deque class TreeNode(object): """ 二叉树结点定义 """ def __init__(self, x): self.val = x self.left = None self.right = None class Tree(obj... 阅读全文