描述
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 farthes
...
描述
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 neares
...
描述
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分析和上一题不同的是,这次是链表,不能随机访问,那么自顶向下的分治法就失
...
描述
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
分析递归分治法解很容易,时间O(n),空间平均O(logn)。
代码Python12345678
...
描述
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 o
...
描述
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.
For example,Given n = 3, your program should return al
...
描述
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?
For example,Given n = 3, there are a total of 5 unique BST
...
描述
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:You may assume that duplicates do not exist in the tree.
分析上一题的姐妹
...
描述
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:You may assume that duplicates do not exist in the tree.
分析经典题,从前序
...
描述
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
...
描述
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point
...
描述
Given a binary tree, flatten it to a linked list in-place.
For example,Given
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look
...
描述
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 d
...
描述
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
/ \
...
描述
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 identica
...