LeetCode
-
Lyang-Never
Never -
展开
-
树(6)——树的前中后序遍历
一、前言原创 2020-08-08 01:10:26 · 281 阅读 · 0 评论 -
树(5)——合并二叉树(T.617)
题目描述题解题解1:# 非递归class Solution: def mergeTrees(self, t1: TreeNode, t2: TreeNode) -> TreeNode: if t1 == None and t2 != None: return t2 if t2 == None and t1 != None: return t1 if t1 == None and t2 ==原创 2020-06-11 13:05:31 · 216 阅读 · 0 评论 -
树(4)——翻转二叉树(T.226)
题目描述题解题解1:# 递归class Solution: def invertTree(self, root: TreeNode) -> TreeNode: if not root:return None if root.left: node_left = self.invertTree(root.left) else: node_left = None if root原创 2020-06-11 12:58:33 · 145 阅读 · 0 评论 -
树(3)——二叉树的直径(T.543)
题目描述题解# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def __init__(self): self.max_r = 0 def diameter原创 2020-06-04 22:47:37 · 189 阅读 · 0 评论 -
树(2)——平衡二叉树(T.110)
题目描述题解# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = None题解1:# 与自己思路相似的一种解法def isBalanced(self, root: TreeNode) -> bool: if not原创 2020-06-04 22:18:53 · 163 阅读 · 0 评论 -
树(1)——二叉树的最大深度(T.104)
题目描述:题解# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = None题解1:# 这个题解是与自己当时思路相接近的一种思路,参考别人的代码,进行了修改。def maxDepth(self, root: TreeNode) ->原创 2020-06-04 21:49:47 · 139 阅读 · 0 评论