上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 51 下一页
摘要: 方法一:迭代 class Solution(object): # 迭代 def preorder(self, root): """ :type root: Node :rtype: List[int] """ res = [] if not root: return res stack = [roo 阅读全文
posted @ 2020-08-30 17:20 人间烟火地三鲜 阅读(182) 评论(0) 推荐(0)
摘要: class Solution(object): def pathSum(self, root, target): """ :type root: TreeNode :type sumt: int :rtype: int """ self.count = 0 myDict = {0: 1} def d 阅读全文
posted @ 2020-08-30 17:18 人间烟火地三鲜 阅读(104) 评论(0) 推荐(0)
摘要: class Solution(object): def levelOrder(self, root): """ :type root: Node :rtype: List[List[int]] """ if not root: return [] ans = [] self.dfs(1, root, 阅读全文
posted @ 2020-08-30 17:15 人间烟火地三鲜 阅读(262) 评论(0) 推荐(0)
摘要: class Solution(object): def sumOfLeftLeaves(self, root): """ :type root: TreeNode :rtype: int """ if not root or (not root.left and not root.right): r 阅读全文
posted @ 2020-08-30 17:14 人间烟火地三鲜 阅读(130) 评论(0) 推荐(0)
摘要: 类似题:https://www.cnblogs.com/panweiwei/p/13585987.html class Solution(object): def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :ty 阅读全文
posted @ 2020-08-30 17:12 人间烟火地三鲜 阅读(170) 评论(0) 推荐(0)
摘要: class Solution(object): def invertTree(self, root): """ :type root: TreeNode :rtype: TreeNode """ if not root: return root.left, root.right = root.rig 阅读全文
posted @ 2020-08-30 17:08 人间烟火地三鲜 阅读(64) 评论(0) 推荐(0)
摘要: class Solution(object): # 递归思路: # (1)如果二叉树为空,节点个数为0 # (2)如果二叉树不为空,二叉树节点个数 = 左子树节点个数 + 右子树节点个数 + 1 def countNodes(self, root): """ :type root: TreeNode 阅读全文
posted @ 2020-08-30 17:07 人间烟火地三鲜 阅读(174) 评论(0) 推荐(0)
摘要: 方法一:DFS class Solution(object): # 方法一:深搜 def rightSideView(self, root): """ :type root: TreeNode :rtype: List[int] """ ans = [] self.dfs(root, 0, ans) 阅读全文
posted @ 2020-08-30 17:05 人间烟火地三鲜 阅读(180) 评论(0) 推荐(0)
摘要: class BSTIterator(object): def __init__(self, root): """ :type root: TreeNode """ self.item = [] while root: self.item.append(root) root = root.left d 阅读全文
posted @ 2020-08-30 17:03 人间烟火地三鲜 阅读(116) 评论(0) 推荐(0)
摘要: 方法一:迭代 class Solution(object): # 迭代 def postorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ if not root: return [] ans = [] 阅读全文
posted @ 2020-08-30 17:01 人间烟火地三鲜 阅读(143) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 51 下一页