【LintCode 简单】13. 字符串查找

1.问题描述:

对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1


2.样例:

如果 source = "source" 和 target = "target",返回 -1

如果 source = "abcdabcdefg" 和 target = "bcd",返回 1


3.代码:

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 or target is None:
            return -1      
        else:
            checkString_1 = list(source)
            checkString_2 = list(target)
            i=len(source)
            j=len(target)
            m=0
            n=0
            if j==0:
                return 0
            elif i==0 and j!=0:
                return -1
            else:
                if j==1:
                    while m



你可能感兴趣的:(LintCode)