
Tree
Arcome
这个作者很懒,什么都没留下…
展开
-
LeetCode #230 - Kth Smallest Element in a BST - Medium
ProblemGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the BST i原创 2016-12-16 17:59:43 · 313 阅读 · 0 评论 -
LeetCode #235 - Lowest Common Ancestor of a Binary Search Tree Easy
ProblemGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: The lowest common ancestor is defined be原创 2016-12-19 18:37:46 · 338 阅读 · 0 评论 -
LeetCode #144 - Binary Tree Preorder Traversal - Medium
相似题目: 二叉树的前序遍历:http://blog.youkuaiyun.com/arcome/article/details/53672748 二叉树的中序遍历: 二叉树的后序遍历:ProblemGiven a binary tree, return the preorder traversal of its nodes' values.Note: Recursive solution原创 2016-12-15 17:12:39 · 414 阅读 · 0 评论 -
LeetCode #145 - Binary Tree Postorder Traversal - Hard
相似题目: 二叉树的前序遍历:http://blog.youkuaiyun.com/Arcome/article/details/53672912 二叉树的中序遍历:http://blog.youkuaiyun.com/arcome/article/details/53672748 二叉树的后序遍历:ProblemGiven a binary tree, return the postorder trav原创 2016-12-19 15:32:14 · 408 阅读 · 0 评论 -
LeetCode #94 - Binary Tree Inorder Traversal - Medium
ProblemGiven a binary tree, return the inorder traversal of its nodes' values.Note: Recursive solution is trivial, could you do it iteratively?ExampleGiven binary tree [1,null,2,3], 1 \ 2原创 2016-12-15 17:04:51 · 284 阅读 · 0 评论 -
LeetCode #404 - Sum of Left Leaves - Easy
ProblemFind 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-12-15 16:58:09 · 293 阅读 · 0 评论 -
LeetCode #226 - Invert Binary Tree - Easy
ProblemInvert a binary tree.Example 4 / \ 2 7 / \ / \1 3 6 9-> 4 / \ 7 2 / \ / \9 6 3 1Algorithm整理一下题意:翻转一棵二叉树。首先想到的当然是递归解法。对每个节点,都翻转左右子树。代码如下。//递归版本,用时0原创 2016-12-15 16:46:46 · 327 阅读 · 0 评论 -
LeetCode #101 - Symmetric Tree - Easy
ProblemGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).Example this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But t原创 2016-11-12 22:02:54 · 404 阅读 · 0 评论 -
LeetCode #394 - Decode String -Medium
ProblemGiven an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is原创 2016-11-12 10:21:42 · 402 阅读 · 0 评论 -
LeetCode #108 - Convert Sorted Array to Binary Search Tree -Medium
ProblemGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.ExampleInput:[1,2,3]Output: 1 /\ 2 3Algorithm整理一下题意:给定一个升序数组,要求将其转化为一课平衡二叉树经典的树类型题目。采原创 2016-11-12 00:16:00 · 353 阅读 · 0 评论 -
LeetCode #337 - House Robber III - Medium
ProblemThe thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After原创 2016-11-09 18:54:04 · 420 阅读 · 0 评论 -
LeetCode #100 - Same Tree - Easy
ProblemGiven 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.ExampleDete原创 2016-11-09 18:36:25 · 449 阅读 · 0 评论 -
LeetCode #104 - Maximum Depth of Binary Tree - Easy
ProblemGiven 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.Subscribe to see which companies ask原创 2016-11-07 21:40:31 · 784 阅读 · 0 评论 -
LeetCode #110 - Balanced Binary Tree - Easy
ProblemGiven 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 dif原创 2016-11-12 22:04:34 · 463 阅读 · 0 评论 -
LeetCode #173 - Binary Search Tree Iterator - Medium
ProblemImplement 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-12-16 18:07:38 · 345 阅读 · 0 评论 -
LeetCode #437 - Path Sum III - Medium
ProblemYou 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 root or a leaf, but it m原创 2016-12-16 18:02:27 · 430 阅读 · 0 评论 -
2017.1.10 算法测试题集 - 1002 - 相等二叉树
Problem给定两棵二叉树,判断这两棵二叉树是否相等。当且仅当两棵树结构相同且对应节点的取值也相同时,两棵二叉树相等。ExampleA: 1 / \ 2 3 / \ \5 6 7B: 1 / \ 2 3 / \ / 5 6 7 C: 1 / \ 2 3 / \ \5 6 7A==C,A!=BAlgorith原创 2017-01-13 17:03:58 · 654 阅读 · 0 评论