libevent源代码之c实现多态
摘要:读libevent源代码,有几点体会,记录如下,希望猎头看到,赶紧来挖我啊。1、libevent源代码是用c语言写的,但是通过结构体实现了c++中的多态,叹为观止。具体介绍如下:struct eventop { const char *name; void *(*init)(struct eve...
阅读全文
posted @
2015-03-25 00:31
xgcode
阅读(235)
推荐(0)
Edit Distance
摘要:该题目和求两个字符串的最长公共子串,有相似之处。关键是求得动态规划方程。即f(m,n)= MIN(f(m-1,n-1),f(m-1,n),f(m,n-1)) + 1;f(m,n)表示长度为m的字符串转换为长度为n的字符串所需的最少步骤。f(m,n)递推是通过和最后一个字符串的比较递推得到。存在一个定...
阅读全文
posted @
2015-03-17 23:05
xgcode
阅读(128)
推荐(0)
Permutation Sequence
摘要:class Solution {public: vector buf; string getPermutation(int n, int k) { string result; int index = 0; for(index =1; index = k) ...
阅读全文
posted @
2015-03-08 19:19
xgcode
阅读(140)
推荐(0)
isSameTree
摘要:class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { if(p == NULL && q == NULL) return true; if(p == NULL || q ==...
阅读全文
posted @
2015-03-08 13:31
xgcode
阅读(103)
推荐(0)
Factorial Trailing Zeroes
摘要:这道题本质上是求阶乘中5的个数。还有一个公式即:[n/k]代表1~n中能被k整除的个数。class Solution{public: int trailingZeroes(int n) { int num= 0; while(n>0) { n...
阅读全文
posted @
2015-03-08 13:23
xgcode
阅读(115)
推荐(0)