From ecc15e23469b9e79982318f6f4b957b4834733b6 Mon Sep 17 00:00:00 2001 From: Azureki Date: Sun, 30 Sep 2018 16:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lc28. Implement strStr().py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lc28. Implement strStr().py b/lc28. Implement strStr().py index f8d6b5c..7c5799c 100644 --- a/lc28. Implement strStr().py +++ b/lc28. Implement strStr().py @@ -5,7 +5,10 @@ def strStr(self, haystack, needle): :type needle: str :rtype: int """ - return haystack.find(needle) + for i in range(len(haystack) - len(needle) + 1): + if haystack[i:i + len(needle)] == needle: + return i + return -1 haystack = "hello"