Skip to content

Commit 0b9737d

Browse files
添加0028.实现strStr python版本暴力解法
1 parent 177823b commit 0b9737d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

problems/0028.实现strStr.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,21 @@ class Solution {
685685
```
686686

687687
Python3:
688-
688+
```python
689+
//暴力解法:
690+
class Solution(object):
691+
def strStr(self, haystack, needle):
692+
"""
693+
:type haystack: str
694+
:type needle: str
695+
:rtype: int
696+
"""
697+
m,n=len(haystack),len(needle)
698+
for i in range(m):
699+
if haystack[i:i+n]==needle:
700+
return i
701+
return -1
702+
```
689703
```python
690704
// 方法一
691705
class Solution:

0 commit comments

Comments
 (0)