@[TOC](Day09: string in python (2))
Leetcode 28: Find the Index of the First Occurrence in a String
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
for i in range(len(haystack)-len(needle)+1):
if haystack[i:i+len(needle)] == needle:
return i
return -1
Leetcode 459:Repeated Substring Pattern
class Solution:
def repeatedSubstringPattern(self, s: str) -> bool:
for i in range(1, len(s)//2+1):
if len(s)%i==0:
sub = s[:i]
if sub*(len(s)//len(sub)) == s:
return True
return False
String in Python:
some useful functions in Python:
List(str)
str.split(‘’)
‘’.join(List)
str.strip() >>> delete extra space of both side
str.islower()
str.capitalize()