问题描述
- 给定源字符串
source
- 目标字符串
target
- 返回目标字符串在源字符串的位置(Form 0 ,-1 is NotFound)
eg:sourece=helloworld , target=llo,返回 2
上代码
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: return i return -1