python leetcode 459. Repeated Substring Pattern

看到了一个很巧妙的做法,能构成的话。s[0]肯定是子串中第一个字符,s[-1]肯定是子串中最后一个字符。取s2=s+s  s2=s2[1:-1] (去掉首尾) 如果在s2中能找到s的话返回True

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

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84751965
今日推荐