Leetcode 459 python 解题报告

AC代码:

class Solution(object):
    def repeatedSubstringPattern(self, str):
        """
        :type str: str
        :rtype: bool
        """
        for i in range(1,len(str)/2+1):
            if len(str)%i != 0:
                continue
            if self.issubstring(str,i):
                return True
        return False
    def issubstring(self,str,i):
        tmp = str[:i]
        for j in range(i,len(str),i):
            if tmp != str[j:j+i]:
                return False
        return True

思路:从1到length/2长度依次进行判断,发现满足情况的substring即可返回True.

你可能感兴趣的:(Leetcode)