-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ28.py
More file actions
25 lines (23 loc) · 704 Bytes
/
Q28.py
File metadata and controls
25 lines (23 loc) · 704 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
25
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
if len(haystack)<len(needle):
return -1
if len(needle) is 0:
return 0
if len(haystack) is 0:
return -1
p=0
while len(haystack)-p+1>len(needle):
if haystack[p]!=needle[0]:
p+=1
else:
flag = True
for i in range(len(needle)):
if haystack[p+i]!=needle[i]:
flag = False
break
if flag:
return p
else:
p+=1
return -1