刚看了一篇文章 《一次谷歌面试趣事》,大概说的是 面试中 遇到一个问题:
两个字符串 :s1 : aabbddeffgsdfs s2: fdscxsad ,怎么高速的 算出 s2 的字符 都在 s1 里出现过。
原文网址:点击打开链接
文中 说了 4种 方法:
1.暴力搜索法 2.排序查找法 3.哈希表法(这个 不太懂) 4. 利用 素数 来算的 方法
当中 最 奇思妙想的 就是 第四种 ,
心中惊叹万分。于是 编写了 以下的 代码。
// find.cpp : 定义控制台应用程序的入口点。
//查找
#include "stdafx.h"
#include <cstring>
#include <climits>
//a~z相应的素数
int primeNumber[26] = {
2,3,5,7,11,13,17,19,23,29,
31,37,41,43,47,53,59,61,67,71,
73,79,83,89,97,101,
};
//p里全部的字母 是否都能在 s里查到,能 返回 true,否则,false
//字母限定 在 a~z
bool isAllMatch(char * string,char * subString){
char * p = string;
<span style="white-space:pre"> </span>long long int mult = 1;
while (*p != '