Posted on 2023-08-21 18:11
Uriel 閱讀(41)
評論(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]