链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3602
题意:给出一棵有n个节点的二叉树和一棵有m个节点的二叉树,给出每个节点的左右子树信息,问这两棵树有几个相同的子树。
思路:树的同构,比赛时没想法,赛后看的别人的解题报告。实际上是给每个节点的左右子树一个哈希值,不用像字符串哈希那么麻烦,直接给每个子树...
分类:
其他好文 时间:
2014-09-05 18:18:31
阅读次数:
251
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4705
题意:给出两棵二叉树A和B,问分别处于A中的子树a和处于B中的子树b结构相同的有多少对。
思路:哈希的想法,不同的数字对应的是不同的结构,比如1代表着单独的叶子结点,2代表着有左子树是叶子结点而没有右子树的子树...每出现一种新的子树情形就记录下来,记录的方式是...
分类:
其他好文 时间:
2014-09-05 18:17:11
阅读次数:
206
Problem Description:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分析:很容易想到的一种解法是将链表中所有的元素保存到数组中,然后每次取中间值进行构造,时间复杂度为O(n),空间复杂度为O(n)。具体...
分类:
其他好文 时间:
2014-09-05 18:14:11
阅读次数:
223
要说slave_skip_errors选项,就不得不提mysql的replication机制,总的来说它分了三步来实现mysql主从库的同步master将改变记录到二进制日志(binary log)中(这些记录叫做二进制日志事件,binary log events);slave将master的bin...
分类:
数据库 时间:
2014-09-05 18:03:51
阅读次数:
380
Sum Root to Leaf Numbers
Total Accepted: 20237 Total
Submissions: 67979My Submissions
Given a binary tree containing digits from 0-9 only,
each root-to-leaf path could represent a numbe...
分类:
其他好文 时间:
2014-09-05 16:12:01
阅读次数:
200
Binary Tree Postorder Traversal
Total Accepted: 28560 Total
Submissions: 92333My Submissions
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given...
分类:
其他好文 时间:
2014-09-05 16:09:01
阅读次数:
172
进入MongoDB下载中心:http://www.mongodb.org/downloadsWe recommend using these binary distributions (官方推荐使用二进制版本!)根据自己的实际系统环境,下载所要的文件,我的是Linux 64-bit.wget htt...
分类:
数据库 时间:
2014-09-05 12:36:11
阅读次数:
282
public class Solution { public List postorderTraversal(TreeNode root) { List result = new ArrayList(); Stack nodeStack = new Stack();...
分类:
其他好文 时间:
2014-09-05 02:08:10
阅读次数:
166
一开始的思路是:中序遍历+判断遍历后的数组,时间空间都不是最优果然超时了 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * ...
分类:
其他好文 时间:
2014-09-04 23:35:50
阅读次数:
393
递归 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode...
分类:
其他好文 时间:
2014-09-04 22:16:00
阅读次数:
228