Created
July 24, 2015 09:34
-
-
Save laoyuan/d3daa37e58cadc24ae30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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