原题地址基本数据结构操作,二叉树的层次遍历。代码: 1 vector > zigzagLevelOrder(TreeNode *root) { 2 vector > res; 3 vector layer; 4 bool l2r = true; 5 ...
分类:
其他好文 时间:
2015-01-29 20:49:11
阅读次数:
169
原题地址Unique Binary Search Trees(参见这篇文章)的升级版做题的时候我在想,这要是把每个二叉树都独立创建一份得多麻烦啊,试试能不能共用"公共部分",试了一下,果然可以,哈哈。trees[i][j]表示数字i到j所能组成的所有二叉树的根节点代码: 1 vector gener...
分类:
其他好文 时间:
2015-01-29 19:04:40
阅读次数:
168
原题地址中序遍历二叉树,如果出现逆序对,则说明不是合法BST代码: 1 bool isValidBST(TreeNode *root) { 2 stack st; 3 int last = 0; 4 bool hasLast = false; 5 ...
分类:
其他好文 时间:
2015-01-29 19:01:22
阅读次数:
154
The problem:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous s...
分类:
其他好文 时间:
2015-01-29 14:00:12
阅读次数:
118
#include #include using namespace std;int cmp(const void *a, const void *b){ return ( *(int *)a - *(int *)b );}int binary_search( int *a, int n, int k...
分类:
其他好文 时间:
2015-01-29 12:30:55
阅读次数:
117
labix.org/v2/mgo/bson 包虽然是MongoDB的golang实现,其中产生唯一ID的算法是独立的,不依赖MongoDB, 提炼这部分的代码如下: package main import ( "crypto/md5" "crypto/rand" "encoding/binary" ...
分类:
其他好文 时间:
2015-01-29 12:16:44
阅读次数:
894
原题地址递归代码谁都会,当然是写非递归代码了。最基本的写法是用一个特殊栈同时保存节点以及节点的左孩子、右孩子是否遍历过。这种思路比较简单,跟递归写法一样很好理解。前序、中序、后序的遍历写法类似。还有一种更"屌"的写法,只需要使用普通栈即可,不需要保存左孩子、右孩子是否遍历过。基本思路是:1. 只要当...
分类:
其他好文 时间:
2015-01-29 11:50:43
阅读次数:
96
Deep in the Amazon jungle, exceptionally tall trees grow that support a rich biosphere of figs and juniper bugs, which happen to be the culinary delight of brown monkeys.
Reaching the canopy of these trees requires the monkeys to perform careful navigati...
分类:
其他好文 时间:
2015-01-29 09:35:41
阅读次数:
209
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni...
分类:
其他好文 时间:
2015-01-28 23:56:50
阅读次数:
231
在控制台输出的话Name = "测试数据",io:format("~ts~n",[Name]).如果是和客户端通信,假如都是utf8编码服务器获取的时候,仍然可以直接通过binary_to_list解码发给客户端的数据的时候,需要用unicode:characters_to_binary("猪头")...
分类:
其他好文 时间:
2015-01-28 19:41:39
阅读次数:
454