随笔分类 -  Tree

摘要:Closest Binary Search Tree Value Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Not 阅读全文
posted @ 2016-10-18 11:24 北叶青藤 阅读(232) 评论(0) 推荐(0)
摘要:Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges mak 阅读全文
posted @ 2016-10-14 02:56 北叶青藤 阅读(269) 评论(0) 推荐(0)
摘要:There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have t 阅读全文
posted @ 2016-10-11 11:48 北叶青藤 阅读(388) 评论(0) 推荐(0)
摘要:Contains Duplicate I Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at l 阅读全文
posted @ 2016-10-10 06:04 北叶青藤 阅读(256) 评论(0) 推荐(0)
摘要:Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it. Not 阅读全文
posted @ 2016-08-09 10:18 北叶青藤 阅读(271) 评论(0) 推荐(0)
摘要:For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible roote 阅读全文
posted @ 2016-08-09 09:17 北叶青藤 阅读(220) 评论(0) 推荐(0)
摘要:Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of th 阅读全文
posted @ 2016-08-07 05:21 北叶青藤 阅读(283) 评论(0) 推荐(0)
摘要:Given a binary search tree and a node in it, find the in-order successor of that node in the BST. 1 public class Solution { 2 3 public TreeNode inorde 阅读全文
posted @ 2016-08-07 00:05 北叶青藤 阅读(204) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-08-06 05:26 北叶青藤 阅读(213) 评论(0) 推荐(0)
摘要:Preorder: 因为是preorder traversal, 我们需要先print root,然后左节点,最后右节点,而且root左边子树一定比右边子树先print出来,所以,我们可以先把当前root的右节点压栈,然后把root的左节点压栈,这样每次从栈里取的时候,可以保证左边节点的root先取 阅读全文
posted @ 2016-08-06 02:47 北叶青藤 阅读(337) 评论(0) 推荐(0)
摘要:Verify Preorder Sequence in Binary Search Tree \Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary se 阅读全文
posted @ 2016-08-05 01:27 北叶青藤 阅读(606) 评论(0) 推荐(0)
摘要:Given a binary tree, find the length of the longest consecutive sequence path (连续的路径,不是从小到大). The path refers to any sequence of nodes from some start 阅读全文
posted @ 2016-08-04 22:40 北叶青藤 阅读(249) 评论(0) 推荐(0)
摘要:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). If two nodes are in the sam 阅读全文
posted @ 2016-08-04 04:19 北叶青藤 阅读(328) 评论(0) 推荐(0)
摘要: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 null node, 阅读全文
posted @ 2016-08-03 23:59 北叶青藤 阅读(343) 评论(0) 推荐(0)
摘要: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 exa 阅读全文
posted @ 2016-08-03 04:48 北叶青藤 阅读(147) 评论(0) 推荐(0)
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its ne 阅读全文
posted @ 2016-08-03 02:31 北叶青藤 阅读(287) 评论(0) 推荐(0)
摘要:Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty. Example:Given bi 阅读全文
posted @ 2016-07-26 01:03 北叶青藤 阅读(208) 评论(0) 推荐(0)
摘要:Given a directed graph, design an algorithm to find out whether there is a route between two nodes. Have you met this question in a real interview? Ye 阅读全文
posted @ 2016-07-20 04:16 北叶青藤 阅读(220) 评论(0) 推荐(0)
摘要:Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) . For each element Ai in the array, count th 阅读全文
posted @ 2016-07-14 21:16 北叶青藤 阅读(362) 评论(0) 推荐(0)
摘要:Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value. 阅读全文
posted @ 2016-07-12 07:23 北叶青藤 阅读(256) 评论(0) 推荐(0)