leetcode--459--repeating string

Source: Internet
Author: User

Problem Description:

Given a non-empty string, determine whether it can be repeated multiple times by one of its substrings. The given string contains only lowercase English letters and is not more than 10000 in length.

Example 1:

Input: "Abab" output: True Explanation: can be repeated two times by sub-string "AB" composition.

Example 2:

Input: "ABA" output: False

Example 3:

Input: "ABCABCABCABC" output: True
Explanation: You can repeat the composition four times by the string "abc". (or the substring "abcabc" repeats two times.) )

Method 1:

1 classsolution (object):2     defRepeatedsubstringpattern (self, s):3         """4 : Type S:str5 : Rtype:bool6         """7n =Len (s)8          forIinchRange (1,n//2 + 1):9             ifn% i = =0:Tentemp =S[:i] Onej =I A                  whileJ < N andtemp = = s[j:j+i]: -J + =I -             ifj = =N: the                 returnTrue -         returnFalse

Official: Scared, scared.

1 classsolution (object):2     defRepeatedsubstringpattern (self, s):3         """4 : Type S:str5 : Rtype:bool6         """7        SS = (S * 2) [1:-1] 8         #Print SS9         returnSinchSs

2018-10-04 20:54:17

leetcode--459--repeating string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.