Path in Tree:

[LeetCode] 112. Path Sum_Easy tag: DFS       input: root, target,   return True if exists sum(root-> leaf) == target else False       1

[LeetCode] 257. Binary Tree Paths_ Easy tag: DFS        input: root,   return all paths from root to leaves

[LeetCode] 113. Path Sum II      input: root, target, return all paths such that sum(root-> leaf) == target else []

[LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive, Divide and conquer   input: root, return max path sum such that any node -> any node.

[LeetCode] 437. Path Sum III_ Easy tag: DFS input: root, return all paths s.t a path sum == target from any node -> any child node .

[LeetCode] 687. Longest Univalue Path_Easy tag: DFS recursive  input:root, return max number of nodes s.t  a path any node -> any node and all nodes have same value,

[LeetCode] 298. Binary Tree Longest Consecutive Sequence_Medium tag: DFS recursive  input: root, return max number of nodes s.t a path any node -> child node and nodes are increasing consecutive order.      1

[LeetCode] 549. Binary Tree Longest Consecutive Sequence II_ Medium tag: DFS recursive  input: root, return max number of nodes s.t a path any node -> any node and nodes are increasing or decreasing consecutive order.

when it becomes path from any node -> any node

we define a helper function.

def helper(root):
if not root: return 0
l, r = helper(root.left), helper(root.right)
l = l if l and condition else 0
# root.val == root.left.val LC. 687
# root.val + 1 == root.left.val LC. 298
r = r if r and condition else 0
self.ans = max(self.ans, possible values)
return max(possible values) # remember that path return should not be left and right both, only choose one.

[LeetCode] questions conclustion_Path in Tree的更多相关文章

  1. [LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal

    Pre: node 先,                      Inorder:   node in,           Postorder:   node 最后 PreOrder Inorde ...

  2. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  3. [LeetCode] 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. [LeetCode] 110. Balanced Binary Tree 平衡二叉树

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  5. [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展平为链表

    Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 ...

  6. [LeetCode] 261. Graph Valid Tree 图是否是树

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  7. [LeetCode] 654. Maximum Binary Tree 最大二叉树

    Given an integer array with no duplicates. A maximum tree building on this array is defined as follo ...

  8. [LeetCode] 655. Print Binary Tree 打印二叉树

    Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...

  9. 【LEETCODE OJ】Binary Tree Postorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...

随机推荐

  1. Qt编写activex控件在网页中运行

    qt能够实现的东西非常多,还可以写activex控件直接在网页中运行.参照qtdemo下的例子即可. 方案一:可执行文件下载:https://pan.baidu.com/s/14ge9ix2Ny0x7 ...

  2. Elasticsearch学习之深入聚合分析二---案例实战

    以一个家电卖场中的电视销售数据为背景,来对各种品牌,各种颜色的电视的销量和销售额,进行各种各样角度的分析,首先建立电视销售的索引,然后 添加几条销售记录 PUT /tvs { "mappin ...

  3. Kerberos认证与攻击学习总结

    0.背景 聆听了n1nty大佬(90后黑客代表)的谆谆指导,学习了n1nty大佬的基本操作,决定总结一下,做一个简要的读书笔记,也把之前自己记录的关于Windows的安全的一些博客能够串联起来.所以首 ...

  4. TOP100summit 2017:小米唐沐等大咖精心挑选的100个年度研发案例实践

    2017年,机器学习.大数据.人工智能等词汇成为软件研发行业的主流,大前端.DevOps.区块链等技术方式成为热点方向:2017年,智能硬件开始成为新的焦点,这一年更被称为智能音箱井喷的一年:2017 ...

  5. 为VS定制一个自己的代码生成器 - 自定义工具开发

    自定义工具开发 为VS定制一个自己的代码生成器 如何在Visual Studio中开发自己的代码生成器插件 你必须懂的 T4 模板:深入浅出 Regasm组件注册工具使用方法 Regasm 注册C# ...

  6. python中super的使用方法

    说白了,super的使用就是要子类要调用父类的方法,我们就用super,那你要有调用的规范,我们明白这个规范就可以了. 在python2和python3中,调用方法不同,注意就是了.Python3.x ...

  7. YARN Architecture

    The fundamental idea of YARN is to split up the functionalities of resource management and job sched ...

  8. ip相关问题解答

    用路由器上网时电脑的设置: ===================== 路由器如何设置另外讨论,现只讲电脑的设置.在Windows XP下: 1.确定桌面上有没有“网上邻居”图标,如果没有,在桌面空白 ...

  9. Python面向对象:继承和多态

    继承与多态简介: 继承可以把父类的所有功能都直接拿过来,这样就不必重零做起,子类只需要新增自己特有的方法,也可以把父类不适合的方法覆盖重写. 动态语言的鸭子类型特点决定了继承不像静态语言那样是必须的. ...

  10. ArcGIS API for javascript开发笔记(四)——GP服务调用之GP模型的规范化制作详解

    感谢一路走来默默陪伴和支持的你~~~ -------------------欢迎来访,拒绝转载------------------- 在之前的利用Python分析GP服务运行结果的输出路径 & ...