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. scanf printf sprintf fprintf

    都是C语言中的函数,但C++保留了这些函数,在头文件iostream中声明了. 1 scanf(格式控制,输出列表) printf (格式控制,输出列表) 举例: #include <iostr ...

  2. document.visibilityState 监听浏览器最小化

    document.hidden:表示页面是否隐藏的布尔值.页面隐藏包括 页面在后台标签页中 或者 浏览器最小化 (注意,页面被其他软件遮盖并不算隐藏,比如打开的 sublime 遮住了浏览器). do ...

  3. 题目1076:N的阶乘(大数乘法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1076 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  4. css零零散散的笔记

    1.div根据内容自适应大小 效果图: html: <body> <div class="parent"> <div class="chil ...

  5. 编译源码 JAVA out of memory

  6. C# DataView操作DataTable

    1.DataView筛选数据 //假设有一个DataTable数据 DataTable dt = new DataTable(); //DataTable转成DefaultView DataView ...

  7. 生成式对抗网络GAN 的研究进展与展望

    生成式对抗网络GAN的研究进展与展望.pdf 摘要: 生成式对抗网络GAN (Generative adversarial networks) 目前已经成为人工智能学界一个热门的研究方向. GAN的基 ...

  8. zabbix触发器表达式详解

    Zabbix触发器的语法如下: {<server>:<key>.<function>(<parameter>)}<operator>< ...

  9. iOS 截屏分享(包含状态栏与不包含状态栏)

    iOS8以上的新方法PhotoKit 监听截图相册变化,取最后一张图片:http://www.hangge.com/blog/cache/detail_1515.html PhotoKit 获取本机相 ...

  10. 浙江工业大学校赛 小M和天平

    小M和天平 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...