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. 深入理解 Neutron -- OpenStack 网络实现(3):VXLAN 模式

    问题导读1.VXLAN 模式下,网络的架构跟 GRE 模式类似,他们的不同点在什么地方?2.网络节点的作用是什么?3.tap-xxx.qr-xxx是指什么? 接上篇:深入理解 Neutron -- O ...

  2. Dropbox 在 Ubuntu 上需要认证授权的问题

    在 Ubuntu 上,通过 Ubuntu软件中心 搜索下载安装了 Dropbox . 运行时,弹出如下图的提示. 输入密码,点击 授权 后,没有出现 Dropbox 的运行界面. 再次点击运行,仍会出 ...

  3. C#访问SQLServer数据库访问帮助类

    SQLServer数据库访问帮助类 这里有一个Mysql帮助类的使用例子可以参考(大同小异) 写了一个Mysql的例子,SQLServer的差不多,一样的 C#简单三层结构设计UI.BLL.DAL 1 ...

  4. smarty 双引号中嵌入变量的方法

    1.如果变量中只包含字符.数字.下划线,可以将变量直接写在双引号中,如:"my name is $name" 2.如果带有其它字符,如“.”,则需要将变量用单引号括起来,如:“my ...

  5. Excel中countif函数的使用方法

    1.countif函数的含义 在指定区域中按指定条件对单元格进行计数(单条件计数) 建议和countifs函数结合起来学习,可以观看小编的经验Excel中countifs函数的使用方法. END 2. ...

  6. LeetCode 49 Group Anagrams(字符串分组)

    题目链接: https://leetcode.com/problems/anagrams/?tab=Description   Problem:给一个字符串数组,将其中的每个字符串进行分组,要求每个分 ...

  7. [原]VNC client 图形化连接 linux

    1. #  vncserver     (启动vncserver,配置密码) 2. vim /root/.vnc/xstartup  (在最后一排添加gnome-session & ) vim ...

  8. Python并行编程的几个要点

    一.基于线程的并行编程 如何使用Python的线程模块 如何定义一个线程 如何探测一个线程 如何在一个子类中使用线程 Lock和RLock实现线程同步 信号实现线程同步 条件(condition)实现 ...

  9. C# 递归与非递归算法与数学公式

    1.递归 递归:程序调用自身的编程技巧称为递归(recursion). 优点是:代码简洁,易于理解. 缺点是:运行效率较低. 递归思想:把问题分解成规模更小,但和原问题有着相同解法的问题. 1)下面是 ...

  10. jquery的$.each如何退出循环和退出本次循环

    https://api.jquery.com/jQuery.each/ We can break the $.each() loop at a particular iteration by maki ...