lintcode 13.字符串查找

class Solution:
    """
    @param: source: source string to be scanned.
    @param: target: target string containing the sequence of characters to match
    @return: a index to the first occurrence of target in source, or -1  if target is not part of source.
    """
    def strStr(self, source, target):
        # write your code here
        if source is None:
            return -1
        if target is None:
            return -1
        l=len(target)
        m=len(source)
        h=m-l+1
        i=0
        while i<=m-l:
            if target==source[i:i+l]:
                return i
            i=i+1
        return -1

你可能感兴趣的:(lintcode 13.字符串查找)