Skip to content

Commit 7b4a4e0

Browse files
authored
Merge pull request #1 from zchoas/zchoas-patch-1
Create 张小胖.md
2 parents 50b792b + 958a807 commit 7b4a4e0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2019.11.24/张小胖.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//暴力破解
2+
class Solution {
3+
public:
4+
int strStr(string haystack, string needle) {
5+
int m = haystack.size();
6+
int n = needle.size();
7+
if (!n) //是否为空
8+
return 0;
9+
for (int i = 0; i < m - n + 1; i++) {
10+
int k = i, j = 0;
11+
while (j < n) {
12+
if (needle[j] == haystack[k]) {
13+
j++;
14+
k++; }
15+
else
16+
break;
17+
}
18+
if (j == n)
19+
return i;
20+
}
21+
return -1;
22+
}
23+
};

0 commit comments

Comments
 (0)