树_遍历
liuchenjane
这个作者很懒,什么都没留下…
展开
-
98. Validate Binary Search Tree
98. Validate Binary Search TreeGiven 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转载 2016-10-11 09:35:46 · 231 阅读 · 0 评论 -
508. Most Frequent Subtree Sum
Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (includi原创 2017-02-09 17:05:37 · 395 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
297. Serialize and Deserialize Binary TreeSerialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or tr转载 2016-11-15 19:32:52 · 294 阅读 · 0 评论 -
331. Verify Preorder Serialization of a Binary Tree
331. Verify Preorder Serialization of a Binary TreeOne way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a nul原创 2016-11-29 22:35:05 · 300 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
236. Lowest Common Ancestor of a Binary TreeGiven a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lo转载 2016-10-27 15:24:27 · 290 阅读 · 0 评论 -
437. Path Sum III
437. Path Sum IIIYou are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the原创 2016-10-23 17:27:33 · 1058 阅读 · 0 评论 -
Path Sum I,II
112. Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below b转载 2016-10-12 08:56:21 · 272 阅读 · 0 评论 -
173. Binary Search Tree Iterator
173. Binary Search Tree IteratorImplement 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 small转载 2016-10-21 18:20:59 · 245 阅读 · 0 评论 -
199. Binary Tree Right Side View
199. Binary Tree Right Side ViewGiven a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Gi原创 2016-10-21 16:28:01 · 248 阅读 · 0 评论 -
96 . Unique Binary Search Trees
96. Unique Binary Search Trees QuestionEditorial Solution My SubmissionsTotal Accepted: 95631Total Submissions: 246245Difficulty: MediumGiven n, how many struct原创 2016-09-15 13:16:45 · 326 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:将一个有序数组转化成平衡的BST,找到中值,作为根节点,再递归分别生成左子树与右子数原创 2016-09-23 16:26:43 · 253 阅读 · 0 评论 -
Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2016-09-25 19:51:19 · 336 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.转载于https://discuss.leetcode.com/topic/8141/sha转载 2016-10-04 20:36:44 · 322 阅读 · 0 评论 -
根据两种不同遍历结果重构二叉树
leetcode原题:题目1 题目2 这里假设给的遍历都有中序遍历,我们先根据先序遍历或后序遍历找到根结点的值,然后据此可判断,在中序遍历的结果向量中,在根节点之前的部分数组组成它的左子树,根节点之后组成它的右子数。采用深度递归dfs。题1:已知中序和后序遍历结果/** * Definition for a binary tree node. * struct TreeNode { *转载 2016-10-08 10:42:36 · 455 阅读 · 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: 1原创 2016-10-10 11:29:06 · 254 阅读 · 0 评论 -
536. Construct Binary Tree from String
You need to construct a binary tree from a string consisting of parenthesis and integers.The whole input represents a binary tree. It contains an integer followed by zero, one or two pairs of parenthes原创 2017-03-12 14:29:23 · 589 阅读 · 0 评论