摘要: class Solution: def treeHeight(self,root): if root==None: return 0 if root.left==None and root.right==None: return 1 lh=self.treeHeight(root.left) ... 阅读全文
posted @ 2019-01-03 11:06 findtruth123 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 一次可以跳一个,也可以跳n个 阅读全文
posted @ 2019-01-03 10:19 findtruth123 阅读(148) 评论(0) 推荐(0) 编辑
摘要: dp[n]=dp[n-1]+dp[n-2] 阅读全文
posted @ 2019-01-03 10:11 findtruth123 阅读(183) 评论(1) 推荐(0) 编辑
摘要: 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) 编辑