Given a binary tree, find the lowest common ancestor of two given nodes in the tree.Node* LCA(Node* root, Node* p, Node* q){ if (root == NULL || p ...
分类:
其他好文 时间:
2014-12-17 01:35:37
阅读次数:
124
Given a binary tree, find the lowest common ancestor of two given nodes in tree. Each node contains a parent pointer which links to its parent.int get...
分类:
其他好文 时间:
2014-12-17 01:28:42
阅读次数:
152
这道题承接Unique Binary Search Trees,只需要返回搜索二叉树的个数,用DP求解。但是这道题需要得到所有树的集合,可以用DFS求解。
原题是这个样子的:
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 all 5 unique BST's...
分类:
其他好文 时间:
2014-12-17 00:23:26
阅读次数:
191
Given a binary search tree(BST), find the lowest common ancestor of two given nodes in the BST.Node* LCA(Node* root, Node* p, Node* q){ if (!root |...
分类:
其他好文 时间:
2014-12-17 00:13:50
阅读次数:
172
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-12-16 22:46:46
阅读次数:
223
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 3
But the following...
分类:
其他好文 时间:
2014-12-16 22:39:34
阅读次数:
214
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 identical and the nodes have the same value.
#include
#...
分类:
其他好文 时间:
2014-12-16 21:08:09
阅读次数:
189
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41964067
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root)....
分类:
其他好文 时间:
2014-12-16 21:07:59
阅读次数:
207
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41964475
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 farthest leaf node....
分类:
其他好文 时间:
2014-12-16 21:07:51
阅读次数:
197
public TreeNode sortedListToBST(ListNode head) {
if (head == null)
return null;
int len = 0;
ListNode nextNode = head;
while (nextNode != null) {
nextNode = nextNode.next;
len++;
}
return buildTree(head, 0, len - 1);
}
public Tree...
分类:
其他好文 时间:
2014-12-16 21:05:05
阅读次数:
159