[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 ...
随机推荐
- shell 获取脚本的绝对路径
basepath=$(cd `dirname $0`; pwd) 在此解释下basepath : dirname $0,取得当前执行的脚本文件的父目录 cd `dirname $0`,进入这个目录(切 ...
- 【Java基础】StringTokenizer用法
写在前面 因为最近在接触hadoop的东西,看示例WordCount的时候里面有一个StringTokenizer的东西特地看了一下 The string tokenizer class allows ...
- vue案例 - v-model实现自定义样式の多选与单选
接,上文:https://www.cnblogs.com/padding1015/p/9265985.html 这两天在玩mpvue,但是下午如果对着文档大眼瞪小眼的话,肯定会睡着的. 想起昨晚的fl ...
- spring整合websocket通信
1. maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...
- zabbix配置server,proxy,agent架构
author: headsen chen date:2018-10-30 19:49:50 环境: centos 6.8_x86_64 zabbix-server: 192.168.1.130 z ...
- sklearn的快速使用
传统的机器学习任务从开始到建模的一般流程是:获取数据 -> 数据预处理 -> 训练建模 -> 模型评估 -> 预测,分类.本文我们将依据传统机器学习的流程,看看在每一步流程中都 ...
- sublime text 3 常见问题总结 pyv8
安装 这个过程下一步下一步就行 激活 在help菜单中选择输入验证码,如下整个都是: ----- BEGIN LICENSE ----- Andrew Weber Single User Licens ...
- Java-06-动手动脑
1.为什么子类的构造方法在运行之前,必须调用父类的构造方法?能不能反过来?为什么不能反过来? 因为子类继承于父类,子类中有父类的对象,父类的构造方法初始化后,子类才能运行自己的构造方法 不能放过来,继 ...
- Nginx防止恶意域名解析
为了防止别人恶意将大量域名解析到自己的网站上面.我们可以对nginx做防止恶意域名解析,这样就只能通过自己的域名访问网站,其他域名就会显示错误500 打开Nginx配置文件nginx.conf,在原来 ...
- 数据挖掘领域十大经典算法之—C4.5算法(超详细附代码)
https://blog.csdn.net/fuqiuai/article/details/79456971 相关文章: 数据挖掘领域十大经典算法之—K-Means算法(超详细附代码) ...