Python 28

def strStr(haystack, needle):
    if not needle:
        return 0

    for index, value in enumerate(haystack):
        if value==needle[0] and haystack[index:len(needle)+index]==needle:
            return index
    return -1
	
print strStr("hello", "ll")
print strStr("aaaaa", "bba")


结果

G:\>python 28.py
2
-1

G:\>


猜你喜欢

转载自blog.csdn.net/qq_36158758/article/details/80216189
今日推荐