摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-04-23 23:40
topass123
阅读(150)
评论(0)
推荐(0)
摘要:
很显然,这与前面的一题的本质区别是,不再是简单的追加。要区分追加的分类。 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None 阅读全文
posted @ 2020-04-23 23:12
topass123
阅读(136)
评论(0)
推荐(0)
摘要:
Python 中使用 collections 中的双端队列 deque() ,其 popleft() 方法是删除最左边的数字,可达到 O(1)时间复杂度;列表 list 的 pop(0) 方法时间复杂度为 O(N) 。 # Definition for a binary tree node. # c 阅读全文
posted @ 2020-04-23 23:03
topass123
阅读(158)
评论(0)
推荐(0)
摘要:
class Solution: def isSymmetric(self, root: TreeNode) -> bool: def recur(L, R): if not L and not R: return True if not L or not R or L.val != R.val: r 阅读全文
posted @ 2020-04-23 16:46
topass123
阅读(195)
评论(0)
推荐(0)
摘要:
class Solution(object): def mirrorTree(self, root): if not root: return None; if not root.left and not root.right: return root; root.left,root.right=r 阅读全文
posted @ 2020-04-23 14:34
topass123
阅读(151)
评论(0)
推荐(0)
摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-04-23 11:38
topass123
阅读(122)
评论(0)
推荐(0)
摘要:
使用dfs(深度优先) 使用递归的平衡因子的方法:9(0,0);15(0,0);7(0,0);20(1,1);3(1,2);很显然还需要+1,才可以实现树的深度记录。 class Solution: def maxDepth(self, root: TreeNode) -> int: if not 阅读全文
posted @ 2020-04-23 09:41
topass123
阅读(113)
评论(0)
推荐(0)
浙公网安备 33010602011771号