树_遍历
liuchenjane
这个作者很懒,什么都没留下…
展开
-
98. Validate Binary Search Tree
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转载 2016-10-11 09:35:46 · 236 阅读 · 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 · 397 阅读 · 0 评论 -
297. Serialize and Deserialize Binary Tree
297. Serialize and Deserialize Binary Tree Serialization 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 · 299 阅读 · 0 评论 -
331. Verify Preorder Serialization of a Binary Tree
331. Verify Preorder Serialization of a Binary Tree One 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 · 306 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
236. Lowest Common Ancestor of a Binary Tree Given 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 · 300 阅读 · 0 评论 -
437. Path Sum III
437. Path Sum III You 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 · 1068 阅读 · 0 评论 -
Path Sum I,II
112. Path Sum Given 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 · 276 阅读 · 0 评论 -
173. Binary Search Tree Iterator
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 small转载 2016-10-21 18:20:59 · 252 阅读 · 0 评论 -
199. Binary Tree Right Side View
199. Binary Tree Right Side View Given 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 · 253 阅读 · 0 评论 -
96 . Unique Binary Search Trees
96. Unique Binary Search Trees Question Editorial Solution My Submissions Total Accepted: 95631Total Submissions: 246245Difficulty: Medium Given n, how many struct原创 2016-09-15 13:16:45 · 331 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 分析:将一个有序数组转化成平衡的BST,找到中值,作为根节点,再递归分别生成左子树与右子数原创 2016-09-23 16:26:43 · 257 阅读 · 0 评论 -
Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2016-09-25 19:51:19 · 342 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree Given 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 · 325 阅读 · 0 评论 -
根据两种不同遍历结果重构二叉树
leetcode原题:题目1 题目2 这里假设给的遍历都有中序遍历,我们先根据先序遍历或后序遍历找到根结点的值,然后据此可判断,在中序遍历的结果向量中,在根节点之前的部分数组组成它的左子树,根节点之后组成它的右子数。采用深度递归dfs。题1:已知中序和后序遍历结果/** * Definition for a binary tree node. * struct TreeNode { *转载 2016-10-08 10:42:36 · 460 阅读 · 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 6 The flattened tree should look like: 1原创 2016-10-10 11:29:06 · 258 阅读 · 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 · 599 阅读 · 0 评论