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")


result

G:\>python 28.py
2
-1

G:\>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325480185&siteId=291194637
28