上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 44 下一页
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None #先是比较树根左右边的是否相等。 阅读全文
posted @ 2020-04-24 23:35 topass123 阅读(172) 评论(0) 推荐(0) 编辑
摘要: class Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not root: return [] res, queue = [], collections.deque() queue.append(root 阅读全文
posted @ 2020-04-24 12:51 topass123 阅读(141) 评论(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-24 11:29 topass123 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 使用中序遍历,返回第k个数来处理 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None 阅读全文
posted @ 2020-04-24 00:10 topass123 阅读(142) 评论(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 23:40 topass123 阅读(146) 评论(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 阅读(130) 评论(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 阅读(148) 评论(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 阅读(192) 评论(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 阅读(144) 评论(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 阅读(119) 评论(0) 推荐(0) 编辑
上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 44 下一页