[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 ...
随机推荐
- Sencha Touch 实战开发培训 视频教程 第二期 第一节
经过忙碌的准备,终于在2014.4.7晚上8:10分开课. 本来预定在8点开课的,不过电脑出了点问题,推迟了. 本期培训一共八节,前两节免费,后面的课程需要付费才可以观看. 本节内容: 了解Sench ...
- Web Service Client使用Microsoft WSE 2.0
我安装了WSE 2.0 SP3,Setup Type选择Runtime.如果想要让Visual Studio 2005以上版本集成WSE需稍费周折,默认集成Visual Studio 2005. 1. ...
- ALTERA FPGA Quartus 指定memory综合使用 M4K块
最近遇到个问题, 使用二位数组方式定义了一个RAM ,但是软件每次 都是使用逻辑单元综合 这块memory , 在ALTERA的网页上 找到了 方法,,在定义的 memory前面加一句画 (* ra ...
- Unity3D笔记 英保通五 鼠标事件与GUI系统双击检测
一.如何使用GUI事件来检测鼠标是否按下的事件: 获取当前事件:var e:Event=Event.current: using UnityEngine; using System.Collectio ...
- html5播放器制作小结
链接:http://snowinmay.net/6rooms/html/music.php 9月份前的版本: 播放,暂停,点赞,播放状态显示. 9.2版本: 下载歌曲,静音,时间倒计时(点击暂停时倒计 ...
- [转]Android中attr自定义标签详解
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:wen= ...
- flask request模块
原文链接: https://blog.csdn.net/u012163234/article/details/53116652 前言 在进行Flask开发中,前端需要发送不同的请求及各种带参数的 ...
- poj1001 Exponentiation【java大数】
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 183034 Accepted: 44062 ...
- VUE中父组件向子组件传递数据 props使用
VUE中,子组件是不能直接访问父组件的数据(一般来说,当然如果你要破坏原则也是可以),如下< <body> <div id="fathercomponent" ...
- ububtu16.04下安装protobuf
重新下载protobuf,我下载的时最新的protobuf-all-3.5.1.tar.gz protobuf网址:https://github.com/google/protobuf/relea ...