一、今日任务
● 字符串总结
● 双指针回顾
二、找出字符串中第一个匹配项的下标
2.1 题目:28. 找出字符串中第一个匹配项的下标
2.2 解题过程
拿到题目能够第一时间想到思路是直接对比,以下是通过代码。
class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
index = -1
if len(haystack) < len(needle):
return -1
elif len(haystack) == len(needle) and haystack != needle:
return -1
else:
hay = 0
nee =0
while hay < len(haystack)-len(needle) + 1:
if haystack[hay] == needle[nee]:
index = hay
flag = 1
while nee < len(needle):
if haystack[hay] != needle[nee]:
hay = index + 1
index = -1
nee = 0
flag = 0
break
nee += 1
hay += 1
if flag:
return index
else:
nee = 0
index = -1
hay += 1
return index
2.3 阅读材料改进
建议二刷看。
三、重复的子字符串
3.1 题目:459. 重复的子字符串
3.2 解题过程
拿到题目第一时间没有思路。
3.3 阅读材料改进
二刷再看。
990

被折叠的 条评论
为什么被折叠?



