随笔分类 - Tree
摘要:Given a binary tree, return all root-to-leaf paths. Example Given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: [ "1->2->5", "1
阅读全文
摘要:House Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constrain
阅读全文
摘要:Invert a binary tree. Invert a binary tree. Invert a binary tree. Example 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 1 /** 2 * Definition of TreeNode: 3 * public
阅读全文
摘要:You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of
阅读全文
摘要:Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores
阅读全文
摘要:Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval. sta
阅读全文
摘要:Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Given n, how many structurally unique BSTs (binary search tr
阅读全文
摘要: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 l
阅读全文
摘要:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. Example Given the below binary tree: 1 / \ 2 3 ret
阅读全文
摘要: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 dept
阅读全文
摘要:Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes. The lowest common ancestor is the node with larg
阅读全文
摘要:Design an iterator over a binary search tree with the following rules: Elements are visited in ascending order (i.e. an in-order traversal) next() and
阅读全文
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Notice You may assume that duplicates do not exist in the tree. Given inor
阅读全文
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). Example Given binary tree {3,9,2
阅读全文
摘要:Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x s
阅读全文
摘要:Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back f
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Example 2 1->2->3 => / \ 1 3 分析:非常简单,用递归
阅读全文
摘要:Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / \ 2 6 / \ /
阅读全文
摘要:Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the right pointer in TreeNode as the next pointer in ListNode. For e
阅读全文

浙公网安备 33010602011771号