![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Tree
文章平均质量分 64
NoooName
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Convert Sorted Array to Binary Search Tree
Q: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.把一个有序的数组转换成二分查找树~ 把中间元素当根节点,然后递归构造左右子树~时间复杂度是O(N)class Solution: # @param num, a list of原创 2014-12-17 22:39:04 · 287 阅读 · 0 评论 -
[Leetcode]Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2015-01-17 17:52:10 · 365 阅读 · 0 评论 -
[Leetcode]Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2015-01-17 22:29:23 · 323 阅读 · 0 评论 -
[Leetcode]Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2015-01-18 20:13:10 · 313 阅读 · 0 评论 -
[Leetcode]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原创 2015-01-19 16:15:35 · 311 阅读 · 0 评论 -
[Leetcode]Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2015-01-17 17:47:40 · 283 阅读 · 0 评论 -
[Leetcode]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 binary tree and sum原创 2015-01-17 19:59:09 · 327 阅读 · 0 评论 -
[Leetcode]Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.跟上一道类似,根据前序遍历和中序遍历重新构造出二叉树~解法也是基本上一样得,代码如下~class Solu原创 2015-01-18 23:30:14 · 306 阅读 · 0 评论 -
[Leetcode]Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2015-01-20 00:17:44 · 439 阅读 · 0 评论 -
[Leetcode]Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2015-01-20 14:30:19 · 358 阅读 · 0 评论 -
[Leetcode]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原创 2015-01-17 23:14:52 · 359 阅读 · 0 评论 -
[Leetcode]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 duplicates do not exist in the tree.根据中序遍历和后序遍历构造二叉树~第一回写的代码如下:class Solution: # @pa原创 2015-01-18 23:18:20 · 314 阅读 · 0 评论 -
[Leetcode]Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.这题要返回树的最大深度~ 递归解法很简单原创 2014-12-17 22:46:40 · 389 阅读 · 0 评论 -
[Leetcode]Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.判断两棵树是不是一样原创 2015-01-14 14:44:59 · 276 阅读 · 0 评论 -
[Leetcode]Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.判断树的最小深度~树的最小深度指的是从根节点到最近的叶节点的距离,所原创 2015-01-14 15:12:13 · 241 阅读 · 0 评论 -
[Leetcode]Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2015-01-15 16:32:41 · 419 阅读 · 0 评论 -
[Leetcode]Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2015-01-16 22:51:26 · 243 阅读 · 0 评论 -
[Leetcode]Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2015-01-16 13:36:17 · 242 阅读 · 0 评论 -
[Leetcode]Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2015-01-16 15:45:48 · 297 阅读 · 0 评论 -
[Leetcode]Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis原创 2015-01-19 15:48:59 · 400 阅读 · 0 评论 -
[Leetcode]Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2015-01-17 14:19:23 · 249 阅读 · 0 评论 -
[Leetcode]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}, 3 / \ 9 20原创 2015-01-20 00:03:21 · 273 阅读 · 0 评论