-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28.py
More file actions
24 lines (24 loc) · 748 Bytes
/
28.py
File metadata and controls
24 lines (24 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def strStr(self, haystack, needle):
fast, slow=0, 0
for fast in range(len(haystack)-len(needle)+1):
if haystack[fast]==needle[slow]:
match = True
record=fast
while slow< len(needle) and fast<len(haystack):
if haystack[fast]==needle[slow]:
fast+=1
slow+=1
else:
match =False
slow=0
break
if match:
return record
else:
fast=fast+1
slow=0
return -1
h="mississippi"
n='pi'
print(Solution().strStr(h, n))