[LEetCode][Python]459. Repeated Substring Pattern

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.

Example 1:

Input: "abab"

Output: True

Explanation: It's the substring "ab" twice.

Example 2:

Input: "aba"

Output: False

Example 3:

Input: "abcabcabcabc"

Output: True

Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)

一开始是没有思路的。。

    def repeatedSubstringPattern2(self, str):
        """
        :type str: str
        :rtype: bool
        """
        ss = (str * 2)[1:-1]
        print ss
        return str in ss
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,929评论 0 0
  • 我自己也没想到对于这本书的读书笔记会连载四篇。前三篇我都是逐字逐句在手机上按出的,老公实在被我的执着所感动,送了一...
    完颜洋洋阅读 416评论 0 1
  • 解决方法就是去除Compile Sources里对应的h文件,这里本该导入的是m文件。
    crushing阅读 234评论 0 0
  • 你悄悄地走了 正如你静静地来 摆动着酒红的秀发 不曾留下一通电话 穿越蓝天的白云 残余独孤的身影 空气中的香味 在...
    鱼教头阅读 301评论 8 8