[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 ...
随机推荐
- Android应用的自动升级、更新模块的实现(转)
我们看到很多Android应用都具有自动更新功能,用户一键就可以完成软件的升级更新.得益于Android系统的软件包管理和安装机制,这一功能实现起来相当简单,下面我们就来实践一下.首先给出界面效果: ...
- 转载->C#中的委托的使用和讲解
C# 中的委托 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容 ...
- Cordova 3.3 开发环境搭建(视频)
图文文章参见: http://www.cnblogs.com/mlzs/p/3332199.html 视频共享链接 百度:http://pan.baidu.com/s/1c0EHfqC
- 4327: JSOI2012 玄武密码[SAM]
4327: JSOI2012 玄武密码 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 263 Solved: 112[Submit][Status] ...
- ASP.NET Session 简单超实用使用总结
一.概述 Session用于存储特定的用户会话所需的信息 . Session对象的引入是为了弥补HTTP协议的不足,HTTP协议是一种无状态的协议. Session中文是“会话”的意思,在ASP.NE ...
- mac操作
资料搜集: mac终端 常用命令操作 mac osx常用快捷键一览 mac chrome快捷键
- beetl的内置函数 (如strutil 工具类)
转自:http://ibeetl.com/guide/ 2.19. 函数调用 Beetl内置函数请参考附录,以下列出了常用的函数 date 返回一个java.util.Date类型的变量,如 date ...
- vs2010版本注释
转:http://www.cnblogs.com/chaselwang/p/3580839.html 关于Visual Studio 20**自动添加头部注释信息 作为一个万年潜水党,不关这一篇文章技 ...
- vue--双向数据绑定
<template> <div id="app"> <p>{{msg}}</p> <input v-model="m ...
- 爬取博主的所有文章并保存为PDF文件
继续改进上一个项目,上次我们爬取了所有文章,但是保存为TXT文件,查看不方便,而且还无法保存文章中的代码和图片. 所以这次保存为PDF文件,方便查看. 需要的工具: 1.wkhtmltopdf安装包, ...