find1 [LeetCode] Implement strStr() 파이썬 (exhaustive search, find, index string) 48ms 걸리는 내 솔루션 class Solution: def strStr(self, haystack: str, needle: str) -> int: m = len(needle) if len(needle) == 0: return 0 for i in range(len(haystack)): if haystack[i] == needle[0] and haystack[i:i+m] == needle: return i else: return -1 20ms 걸리는 솔루션 class Solution: def strStr(self, haystack: str, needle: str) -> int: m, n = len(haystack), len(needle) for i in range(m - n + 1): if haystac.. 2021. 3. 29. 이전 1 다음