题目链接:
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
if not needle:
return 0
size=len(needle)
for i in range(len(haystack)-size+1):
if haystack[i:i+size]==needle:
return i
return -1
class Solution:
def repeatedSubstringPattern(self, s: str) -> bool:
if not s:
return True
#return s in (s+s)[1:-1]
temp =''
for i in s:
temp+=i
if len(s)%len(temp)==0 and temp*(len(s)//len(temp))==s and len(s)//2>=len(temp):
return True
return False
总结:字符串两个easy题目,两个低级解法。