cpp-interview/Algorithm/BruteForceStringMatch.h

14 lines
289 B
C
Raw Normal View History

2018-02-11 01:08:43 +08:00
// 蛮力字符串匹配
int BruteForceStringMatch(vector<char>& Total, vector<char>& Part)
{
int i, j;
for (i = 0; i < Total.size() - Part.size(); ++i) {
j = 0;
while (j < Part.size() && Part[j] == Total[i + j]) {
++j;
if (j == Part.size())
return i;
}
}
return -1;
}