上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 33 下一页
摘要: class Solution: def pathSum(self, root: TreeNode, sum: int) -> int: if not root: return 0 def dfs(node,sums): left=right=0 temp=[num+node.val for num 阅读全文
posted @ 2019-11-21 19:52 欣姐姐 阅读(152) 评论(0) 推荐(0) 编辑
摘要: class Solution: def longestUnivaluePath(self, root: TreeNode) -> int: self.ans=0 def arrow_length(node): if not node: return 0 left_length=arrow_lengt 阅读全文
posted @ 2019-11-21 19:25 欣姐姐 阅读(161) 评论(0) 推荐(0) 编辑
摘要: class Solution: def isUnivalTree(self, root: TreeNode) -> bool: if not root: return True else: a=root.val if root.left and root.left.val!=a: return Fa 阅读全文
posted @ 2019-11-21 18:56 欣姐姐 阅读(116) 评论(0) 推荐(0) 编辑
摘要: class Solution: def sumOfLeftLeaves(self, root: TreeNode) -> int: if not root: return 0 if root and root.left and not root.left.left and not root.left 阅读全文
posted @ 2019-11-20 15:46 欣姐姐 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 并没有理解这种递归想法: class Solution: def __init__(self): self.ans=None def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'Tree 阅读全文
posted @ 2019-11-19 17:24 欣姐姐 阅读(154) 评论(0) 推荐(0) 编辑
摘要: class Solution: def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': if p.val>q.val: p,q=q,p if q.val<root.va 阅读全文
posted @ 2019-11-19 16:26 欣姐姐 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 暴力法: class Solution: def countNodes(self, root: TreeNode) -> int: if not root: return 0 else: return 1+self.countNodes(root.left)+self.countNodes(root 阅读全文
posted @ 2019-11-19 15:48 欣姐姐 阅读(168) 评论(0) 推荐(0) 编辑
摘要: class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if not root: return root def helper(node): if node: if node.left or node.right: node 阅读全文
posted @ 2019-11-19 15:08 欣姐姐 阅读(134) 评论(0) 推荐(0) 编辑
摘要: class Solution: def hasPathSum(self, root: TreeNode, sum: int) -> bool: if not root: return False if not root.left and not root.right and sum - root.v 阅读全文
posted @ 2019-11-17 22:24 欣姐姐 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 好开心,我终于独立完成了!!!! class Solution: def sortedArrayToBST(self, nums: List[int]) -> TreeNode: if len(nums)==0: return None i=len(nums)//2 root=TreeNode(nu 阅读全文
posted @ 2019-11-15 11:51 欣姐姐 阅读(121) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 33 下一页