From 0b9737d7541870e8f68d728fd0a0197d281b4c1d Mon Sep 17 00:00:00 2001 From: JaneyLin <105125897+janeyziqinglin@users.noreply.github.com> Date: Thu, 16 Jun 2022 21:24:24 -0500 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00028.=E5=AE=9E=E7=8E=B0strStr?= =?UTF-8?q?=20python=E7=89=88=E6=9C=AC=E6=9A=B4=E5=8A=9B=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0028.实现strStr.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/problems/0028.实现strStr.md b/problems/0028.实现strStr.md index 1cdd5292..00997907 100644 --- a/problems/0028.实现strStr.md +++ b/problems/0028.实现strStr.md @@ -685,7 +685,21 @@ class Solution { ``` Python3: - +```python +//暴力解法: +class Solution(object): + def strStr(self, haystack, needle): + """ + :type haystack: str + :type needle: str + :rtype: int + """ + m,n=len(haystack),len(needle) + for i in range(m): + if haystack[i:i+n]==needle: + return i + return -1 +``` ```python // 方法一 class Solution: