We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent df9cfca commit 26c0dfeCopy full SHA for 26c0dfe
Find_the_Index_of_the_First_Occurrence_in_a_String/Solution_1.py
@@ -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