Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594
判断一个字符串是不是由某个子串重复几次构成,参考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]

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理