[LeetCode][Python3] 28. Implement strStr()
2018. 9. 12. 00:47 |
프로그래밍/LeetCode
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 알고리즘에 익숙해지면 추가 풀이도 올려두겠다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 665. Non-decreasing Array (0) | 2018.09.13 |
---|---|
[LeetCode][Python3] 705. Design HashSet (0) | 2018.09.12 |
[LeetCode][Python3] 706. Design HashMap (0) | 2018.09.12 |
[LeetCode][Python3] 35. Search Insert Position (0) | 2018.09.12 |
[LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 |
[LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 |
[LeetCode][Python3] 7. Reverse Integer (0) | 2018.09.11 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2018.09.11 |
최근에 달린 댓글 최근에 달린 댓글