tree
文章平均质量分 50
伊萨卡钢琴家
这个作者很懒,什么都没留下…
展开
-
Leetcode 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th原创 2016-01-27 01:13:35 · 322 阅读 · 0 评论 -
Leetcode 173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()原创 2016-01-29 10:58:48 · 250 阅读 · 0 评论 -
Leetcode 156 Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin原创 2016-01-28 23:04:44 · 303 阅读 · 0 评论 -
Leetcode 298 Binary Tree Longest Consecutive Sequence
给一个binary tree, 问你怎么找其中最长的连续递增的path.也可以从前往后的遍历。然后用递归变成从后往前http://www.chenguanghe.com/binary-tree-longest-consecutive-sequence/原创 2016-01-28 23:03:24 · 354 阅读 · 0 评论 -
Leetcode 270 Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note: Given target value is a floating point. You are guaranteed to have only one u原创 2016-01-28 22:59:52 · 282 阅读 · 0 评论 -
Leetcode 250 Count Univalue Subtrees
Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5原创 2016-01-28 22:54:25 · 675 阅读 · 0 评论 -
Leetcode 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7},用一个栈维护一层的节点public Array原创 2016-01-27 11:30:36 · 280 阅读 · 0 评论 -
Leetcode tree题型总结
对我来说,Tree 是 Leetcode中最简单的题,因为Tree的题型比较单一,方法也比较固定。98. Validate Binary Search Tree https://leetcode.com/problems/validate-binary-search-tree/我觉得这道题和Symmetric Tree比较像都是考察树的结构,要判断这个需要判断左右节点,采用从底原创 2016-01-27 11:28:21 · 757 阅读 · 0 评论 -
Leetcode 124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The原创 2016-01-27 01:36:15 · 273 阅读 · 0 评论 -
114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:analysis原创 2016-01-27 01:28:23 · 269 阅读 · 0 评论 -
Leetcode tree的碎碎念
关于Leetcode 中的Tree应该是最简单的一类题。绝大部分题考察队树的遍历,前序,中序,后序对树的遍历。然后还有各种变形体考对树的遍历,还有其他题型考对树的前序遍历 path sum, the maximum depth, and the minimum depth of the tree. They all need to record return原创 2016-01-29 11:34:04 · 194 阅读 · 0 评论