LintCode 13 – Python 3 (Week 09 – 01)

class Solution:
    """
    @param source: 
    @param target: 
    @return: return the index
    """
    def strStr(self, source, target):
        # Write your code here
            
        if len(target) == 0:
            return 0
        
        if len(source) - len(target) < 0:
            return -1
            
        for i in range(len(source) - len(target) + 1):
            if source[i:i+len(target)] == target:
                return i
                
        return -1

Leave a comment

Design a site like this with WordPress.com
Get started