Leetcode 459. Repeated Substring Pattern,leetcoderepeated
分享于 点击 42403 次 点评:191
Leetcode 459. Repeated Substring Pattern,leetcoderepeated
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
在discuss里面看到了一个方法,让人叹为观止!
def repeatedSubstringPattern(self, str):
"""
:type str: str
:rtype: bool
"""
if not str:
return False
ss = (str + str)[1:-1]
return ss.find(str) != -1
Basic idea:
相关文章
- 暂无相关文章
用户点评