Tree
文章平均质量分 79
likecool21
这个作者很懒,什么都没留下…
展开
-
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原创 2014-04-22 09:21:03 · 2596 阅读 · 0 评论 -
LeetCode刷题笔录Covert 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.思路并不难。每次选链表的中间元素原创 2014-08-01 12:47:11 · 622 阅读 · 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.原创 2014-08-19 10:58:50 · 713 阅读 · 0 评论 -
LeetCode刷题笔录Binary Tree Post Order 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原创 2014-08-18 01:06:02 · 715 阅读 · 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原创 2014-08-20 00:08:37 · 683 阅读 · 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原创 2014-07-16 05:23:59 · 789 阅读 · 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原创 2014-07-13 00:36:34 · 740 阅读 · 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.原创 2014-07-13 00:57:09 · 1020 阅读 · 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 / \原创 2014-08-02 00:24:08 · 771 阅读 · 0 评论 -
LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.这题可以kan'chu'lai原创 2014-05-29 06:01:16 · 789 阅读 · 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原创 2014-05-29 02:48:06 · 712 阅读 · 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原创 2014-06-25 13:09:24 · 777 阅读 · 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原创 2014-04-29 13:02:49 · 751 阅读 · 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原创 2014-04-09 15:15:58 · 6809 阅读 · 2 评论 -
Largest BST in a Binary Tree
一到面试题,挺有意思的。简单做法是对于每个node都进行一遍isBST的测试,找出最大的那个。public static int largestBSTNaive(TreeNode root){ if(isBST(root)){ return size(root); } return Math.max(largestBSTNaive(root.left), largestB原创 2015-03-05 12:11:59 · 1860 阅读 · 0 评论