头像

带翅膀的猫

时光荏苒,我们一直都在

《LeetCode刷题(Easy Rank):459. Repeated Substring Pattern》

 3周前  •   LeetCode  •     •   6  •   0

Question:

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.)

Solution:

Pythonclass Solution:
    def repeatedSubstringPattern(self, s):
        """
        :type s: str
        :rtype: bool
        """
        ss = (s + s)[1:-1]
        return ss.find(s) != -1

 

上一篇:
下一篇:

 评论


 已有0条评论

    还没有任何评论,你来说两句吧!