首页 > 编程 > Python > 正文

Leetcode 459 python 解题报告

2019-11-08 03:24:41
字体:
来源:转载
供稿:网友

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.


上一篇:Python中itertools的用法

下一篇:python练习2

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表