摘要: 题目:求字符串的最长非重复子序列。比如字符串“dabaccdeff”,它的最长非重复子序列为“dabcef”这道题目与面试题35:第一个只出现一次的字符非常相似。都可以通过对字符串球哈希来解。View Code #include<iostream>#include <stack> #include<stdlib.h>using namespace std;void print(char *s,int len,char *hashtable);int NoReplicatedSubstring(char *s,int len){ const int table 阅读全文
posted @ 2012-10-13 16:20 xwdreamer 阅读(2491) 评论(0) 推荐(1) 编辑
摘要: 题目:输入一棵二叉树的根节点,求该树的深度。从根节点到叶子结点一次经过的结点形成树的一条路径,最长路径的长度为树的深度。根节点的深度为1。解体思路:如果根节点为空,则深度为0,返回0,递归的出口如果根节点不为空,那么深度至少为1,然后我们求他们左右子树的深度,比较左右子树深度值,返回较大的那一个通过递归调用代码实现View Code #include<iostream>#include<stdlib.h>using namespace std;struct BinaryTreeNode{ int m_nValue; BinaryTreeNode* m_pLeft; Bi 阅读全文
posted @ 2012-10-13 14:44 xwdreamer 阅读(25049) 评论(2) 推荐(0) 编辑
摘要: 题目:求一个数的质因数分解,比如输入90,输出2*3*3*5。解体思路:要求一个数n的质因数分解,首先求出n以内的所有质数,将其放入prime[]数组内,然后再让prime[i]去除n,如果能够整除,那么这个prime[i]就是n的质因数,否则不是。求prime[]的方法是筛法求素数。代码实现View Code #include<iostream>#include<stdlib.h>using namespace std;bool isPrime(int number);//判断number是否为素数void PrintPrime(int number);//查找0.. 阅读全文
posted @ 2012-10-13 13:49 xwdreamer 阅读(2263) 评论(7) 推荐(2) 编辑