1.(字符串)-子字符串位置查找
如:给定acdbcdbdse,查询:dbd。返回5
Python:
class Solution:
def strStr(self, source, target):
if source is None or target is None:
return -1
for i in range(len(source) - len(target) + 1):
for j in range(len(target)):
if source[i + j] != target[j]:
break
else: #python:for else;for内全部正常执行完毕(不执行break)时,执行else
return i
return -1
s=Solution()
a=s.strStr('acdbcdbdse','dbd')
print(a)