Skip to content

Commit 26c0dfe

Browse files
authored
Create Solution_1.py
1 parent df9cfca commit 26c0dfe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution(object):
2+
def strStr(self, haystack, needle):
3+
"""
4+
:type haystack: str
5+
:type needle: str
6+
:rtype: int
7+
"""
8+
if not needle:
9+
return 0
10+
11+
n, m = len(haystack), len(needle)
12+
13+
for i in range(n - m + 1):
14+
match = True
15+
for j in range(m):
16+
if haystack[i + j] != needle[j]:
17+
match = False
18+
break
19+
if match:
20+
return i
21+
22+
return -1

0 commit comments

Comments
 (0)