Posted on 2023-08-21 18:11
Uriel 阅读(35)
评论(0) 编辑 收藏 引用 所属分类:
字符串处理 、
闲来无事重切Leet Code
判断一个字符串是不是由某个子串重复几次构成,参考Discussion get了绝妙解法 -> https://leetcode.com/problems/repeated-substring-pattern/solutions/826151/python-c-java-js-go-by-fold-and-find-w-simple-proof/
1 #459
2 #Runtime: 17 ms (Beats 88.78%)
3 #Memory: 13.7 MB (Beats 55.12%)
4
5 class Solution(object):
6 def repeatedSubstringPattern(self, s):
7 """
8 :type s: str
9 :rtype: bool
10 """
11 return s in (s + s)[1:-1]