Problem :

https://leetcode.com/problems/implement-strstr/description/


My Solution :

class Solution:
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
if not needle:
return 0
for i in range(len(haystack)-len(needle)+1):
for j, n in enumerate(needle):
if n != haystack[i+j]:
break
else:
return i
return -1


Comment :

일단 이렇게 Brute force 방식으로 먼저 풀어둔다. KMP 알고리즘에 익숙해지면 추가 풀이도 올려두겠다.