随笔分类 -  DFS

深搜
摘要:代码一 class Solution(object): # 思路:用前序式DFS,从root到叶子。 def binaryTreePaths(self, root): """ :type root: TreeNode :rtype: List[str] """ if not root: return 阅读全文
posted @ 2020-09-30 15:25 人间烟火地三鲜 阅读(125) 评论(0) 推荐(0)
摘要:class Solution(object): def isUnivalTree(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True return self.dfs(root) def dfs 阅读全文
posted @ 2020-09-30 15:13 人间烟火地三鲜 阅读(76) 评论(0) 推荐(0)
摘要:代码一 用list或者字符串方式返回二叉树的所有路径:https://www.cnblogs.com/panweiwei/p/13752895.html class Solution(object): def pathSum(self, root, sum): """ :type root: Tre 阅读全文
posted @ 2020-09-30 14:57 人间烟火地三鲜 阅读(146) 评论(0) 推荐(0)
摘要:一、用list返回二叉树的所有路径 class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None class Solution(object): def findAllPa 阅读全文
posted @ 2020-09-30 08:55 人间烟火地三鲜 阅读(291) 评论(0) 推荐(0)
摘要:方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # 思路:层序模板。 def maxDepth(self, root): """ :type 阅读全文
posted @ 2020-09-13 16:16 人间烟火地三鲜 阅读(106) 评论(0) 推荐(0)
摘要:方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # BFS def kthLargest(self, root, k): """ :type 阅读全文
posted @ 2020-09-13 16:13 人间烟火地三鲜 阅读(109) 评论(0) 推荐(0)
摘要:class Solution(object): def isCousins(self, root, x, y): """ :type root: TreeNode :type x: int :type y: int :rtype: bool """ # 用字典记录每个节点的父节点、以及该节点的深度( 阅读全文
posted @ 2020-09-13 16:01 人间烟火地三鲜 阅读(119) 评论(0) 推荐(0)
摘要:DFS应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): def increasingBST(self, root): """ :type root: TreeNod 阅读全文
posted @ 2020-09-13 15:57 人间烟火地三鲜 阅读(129) 评论(0) 推荐(0)
摘要:class Solution(object): def leafSimilar(self, root1, root2): """ :type root1: TreeNode :type root2: TreeNode :rtype: bool """ res1 = [] self.dfs(root1 阅读全文
posted @ 2020-09-13 15:54 人间烟火地三鲜 阅读(128) 评论(0) 推荐(0)
摘要:方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): def maxDepth(self, root): """ :type root: Node 阅读全文
posted @ 2020-09-13 15:43 人间烟火地三鲜 阅读(150) 评论(0) 推荐(0)
摘要:方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # BFS def findBottomLeftValue(self, root): """ 阅读全文
posted @ 2020-09-13 15:36 人间烟火地三鲜 阅读(205) 评论(0) 推荐(0)
摘要:方法一:BFS模板的应用。 总结的DFS、BFS模板参考:https://www.cnblogs.com/panweiwei/p/13065661.html class Solution(object): # BFS def kthSmallest(self, root, k): """ :type 阅读全文
posted @ 2020-09-13 15:20 人间烟火地三鲜 阅读(135) 评论(0) 推荐(0)