[LeetCode] questions conclustion_Path in Tree
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的更多相关文章
- [LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal
Pre: node 先, Inorder: node in, Postorder: node 最后 PreOrder Inorde ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- [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 ...
- [LeetCode] 110. Balanced Binary Tree 平衡二叉树
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- [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 ...
- [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), ...
- [LeetCode] 654. Maximum Binary Tree 最大二叉树
Given an integer array with no duplicates. A maximum tree building on this array is defined as follo ...
- [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 ...
- 【LEETCODE OJ】Binary Tree Postorder Traversal
Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...
随机推荐
- SSL & TLS & STARTTLS
https://www.fastmail.com/help/technical/ssltlsstarttls.html SSL vs TLS vs STARTTLS There's often qui ...
- Linux日志五大命令详解
1.who 命令 who 命令查询 utmp 文件并报告当前登录的每个用户.Who 的缺省输出包括用户名.终端类型.登录日期及远程主机.使用该命令,系统管理员可以查看当前系统存在哪些不法用户,从而对其 ...
- cout快捷转换进制
cout<<hex<<i<<endl; //输出十六进制数 cout<<oct<<i<<endl; //输出八进制数 cout& ...
- 1007: [HNOI2008]水平可见直线[维护下凸壳]
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7184 Solved: 2741[Submit][Sta ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验八:PS/2模块② — 键盘与组合键
实验八:PS/2模块② — 键盘与组合键 实验七之际,我们学习如何读取PS/2键盘发送过来的通码与断码,不过实验内容也是一键按下然后释放,简单按键行为而已.然而,实验八的实验内容却是学习组合键的按键行 ...
- Swift - 判断应用是否是第一次启动(或当前版本是否第一次启动)
1 实现原理 (1)我们会发现许多 App 在一次启动时会显示一个新手引导页(下次启动就不会再显示) (2)其判断原理就是在 AppDelegate 里的 didFinishLaunchingWi ...
- MapReduce实例(数据去重)
数据去重: 原理(理解):Mapreduce程序首先应该确认<k3,v3>,根据<k3,v3>确定<k2,v2>,原始数据中出现次数超过一次的数据在输出文件中只出现 ...
- Python正则表达式匹配猫眼电影HTML信息
爬虫项目爬取猫眼电影TOP100电影信息 项目内容来自:https://github.com/Germey/MaoYan/blob/master/spider.py 由于其中需要爬取的包含电影名字.电 ...
- chrome Sources选项卡 设置JavaScript事件断点
chrome console 可以查看执行的javascript么? 举个例子: 比如这张图片,163邮箱,我点击上一封邮件和下一封邮件执行的是javascript方法. 虽然在chrome的cons ...
- iOS-CoreLocation简单介绍(转载)
一.简介 1.在移动互联网时代,移动app能解决用户的很多生活琐事,比如 (1)导航:去任意陌生的地方 (2)周边:找餐馆.找酒店.找银行.找电影院 2.在上述应用中,都用到了地图和定位功能,在iOS ...