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 ...
分类:
其他好文 时间:
2014-10-12 19:12:18
阅读次数:
158
Validate Binary Search Tree
Total Accepted: 23828 Total
Submissions: 91943My Submissions
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined...
分类:
其他好文 时间:
2014-10-12 17:40:38
阅读次数:
180
题目大意:给出一棵树,将树中的一个节点去掉之后,这棵树会分裂成一些联通块,求去掉哪些点之后,所有联通块的大小不超过所有节点的一半,并按顺序输出。
思路:基础的子树统计问题,只要深搜一遍就可以出解。这个步骤和求树的重心很像,是树分治的基础。
CODE:
#include
#include
#include
#include
#define MAX 10010
u...
分类:
其他好文 时间:
2014-10-12 12:07:57
阅读次数:
168
观察文件类型statfile: ASCII data binary 或者有没有用到动态函式库type-t显示他的意义 file. alias. builtin内建-a列出PATH中-p显示外部指令的完整文件名档案特殊权限: id(列出自己信息)在原来改权限3个数字之前再加一个1个数字 chmod n...
分类:
系统相关 时间:
2014-10-12 11:14:07
阅读次数:
228
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; ...
分类:
其他好文 时间:
2014-10-12 07:47:07
阅读次数:
168
456789101112131415161718192021// Return #nodes that matches P or Q in the subtree.int countMatchesPQ(Node *root, Node *p, Node *q) { if (!root) retur....
分类:
其他好文 时间:
2014-10-12 06:40:37
阅读次数:
160
Convert Sorted List to Binary Search Tree
Total Accepted: 21420 Total
Submissions: 78476My Submissions
Given a singly linked list where elements are sorted in ascending order, convert it ...
分类:
其他好文 时间:
2014-10-12 00:00:36
阅读次数:
250
题目:Binary Tree Preorder Traversal二叉树的前序遍历,同样使用栈来解,代码如下: 1 struct TreeNode { 2 int val; 3 TreeNode* left; 4 TreeNode* righ...
分类:
其他好文 时间:
2014-10-11 22:44:56
阅读次数:
222
题目:Binary Tree Inorder Traversal二叉树的中序遍历,和前序、中序一样的处理方式,代码见下: 1 struct TreeNode { 2 int val; 3 TreeNode* left; 4 TreeNode* ...
分类:
其他好文 时间:
2014-10-11 22:03:26
阅读次数:
233