Skip to content

Instantly share code, notes, and snippets.

@laoyuan
Created July 24, 2015 09:34
Show Gist options
  • Save laoyuan/d3daa37e58cadc24ae30 to your computer and use it in GitHub Desktop.
Save laoyuan/d3daa37e58cadc24ae30 to your computer and use it in GitHub Desktop.
class Solution(object):
def strStr(self, source, target):
if source == None or target == None:
return -1
len_t = len(target)
if len_t == 0:
return 0
pos_s = 0
for char_s in source[:-len_t]:
pos_t = 0
for char_t in target:
if char_t != source[pos_s + pos_t]:
break
pos_t = pos_t + 1
if pos_t == len_t:
return pos_s
pos_s = pos_s + 1
return -1
a = Solution()
print a.strStr('abc', 'abc')
print a.strStr('abc', 'bc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment