Skip to content

Instantly share code, notes, and snippets.

@prat0318
Created January 3, 2014 23:15
Show Gist options
  • Save prat0318/8248575 to your computer and use it in GitHub Desktop.
Save prat0318/8248575 to your computer and use it in GitHub Desktop.
/* return a pointer to the first occurrence of needle in haystack (if none, return NULL) */ char *strstr(char *haystack, char *needle); haystack - N needle - K
def strstr(haystack, needle):
for i in range(len(haystack) - len(needle) + 1):
match = True
for j in range(len(needle)):
if haystack[i+j] != needle[j]:
match = False
break
if match == True: return i
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment