Problem
# Implement strStr().
#
# Returns the index of the first occurrence of needle in x,
# or -1 if needle is not part of x.
AC
class Solution():
def strStr(self, x, needle):
for i in range(len(x)-len(needle)+1):
if x[i:i+len(needle)] == needle:
return i
return -1
if __name__ == "__main__":
assert Solution().strStr("a", "") == 0
assert Solution().strStr("a", "a") == 0
assert Solution().strStr("abababcdab", "ababcdx") == -1
assert Solution().strStr("hello", "ll") == 2