Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 79bcda8

Browse files
zhangzz2015gitbook-bot
authored andcommitted
GitBook: [greyireland#103] No subject
1 parent f55d977 commit 79bcda8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

‎SUMMARY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [二叉搜索树](advanced\_algorithm/binary\_search\_tree.md)
3030
* [回溯法](advanced\_algorithm/backtrack.md)
3131
* [其他的技巧](suan-fa-si-wei/qi-ta-de-ji-qiao.md)
32+
* [字符串操作](suan-fa-si-wei/zi-fu-chuan-cao-zuo.md)
3233

3334
## 面试公司
3435

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 字符串操作
2+
3+
### 字符串匹配方法
4+
5+
#### KMP方法
6+
7+
#### Rolling hash方法
8+
9+
```cpp
10+
// Some code
11+
int hasDup(string& s, int val)
12+
{
13+
]et * 26 + s[i];
14+
ret = ret%prim;
15+
baseVal *=26;
16+
baseVal = baseVal%prim;
17+
}
18+
19+
record[ret].push_back(0);
20+
for(int i = val ; i< s.size(); i++)
21+
{
22+
ret = (ret*26 + s[i] - baseVal*s[i-val]%prim + prim)%prim;
23+
auto it = record.find(ret);
24+
if(it!=record.end())
25+
{
26+
for(int j=0; j< (*it).second.size(); j++)
27+
{
28+
if(isSameString(s, (*it).second[j], i-val+1, val))
29+
return (*it).second[j];
30+
}
31+
record[ret].push_back(i-val+1);
32+
}
33+
else
34+
{
35+
record[ret].push_back(i-val+1);
36+
}
37+
}
38+
return -1;
39+
}
40+
41+
bool isSameString(string& s, int s1, int s2, int size)
42+
{
43+
for(int i=0; i< size; i++)
44+
{
45+
if(s[s1+i] != s[s2+i])
46+
return false;
47+
}
48+
return true;
49+
}
50+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /