1. 程式人生 > >Leetcode 459 python 解題報告

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.