459. 重复的子字符串

class Solution(object):
    def repeatedSubstringPattern(self, s):
        """
        :type s: str
        :rtype: bool
        """
    # 方法一:效率稍微好一些
# n = len(s) # for i in range(1, n//2+1): # if n % i == 0: # a = s[:i] # j = i # while j < n and s[j:j+i] == a: # j += i # if j == n: # return True # return False
    # 方法二:效率差

length
= len(s) for i in range(1, length // 2 + 1): if s[i] == s[0] and s[:i] * (length // i) == s: return True return False

 

posted @ 2019-02-21 14:22  小学弟-  阅读(114)  评论(0编辑  收藏  举报