Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.  You may assume the given string consists of lowercase English letters only and its length  will not exceed 10000. 

Example 1:

Input: "abab"

Output: True

Explanation: It's the substring "ab" twice.



Example 2:

Input: "aba"

Output: False



Example 3:

Input: "abcabcabcabc"

Output: True

Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)

Source: leetcode | Difficulty: EASY
Tags: String algorithms

Starter code: class Solution:
    def repeatedSubstringPattern(self, s: str) -> bool:
        

Solutions:
class Solution:

	def repeatedSubstringPattern(self, s):
		return s in (s + s)[1:-1]


class Solution:

	def repeatedSubstringPattern(self, s):
		if not s:
			return False
		ss = (s + s)[1:-1]
		return s in ss


class Solution:

	def repeatedSubstringPattern(self, s):
		double_s = s + s
		return s in double_s[1:len(double_s) - 1]


class Solution:

	def repeatedSubstringPattern(self, s):
		return any((s[:i] * (len(s) // i) == s for i in range(1, len(s) // 2 + 1) if len(s) % i == 0))


class Solution:

	def repeatedSubstringPattern(self, s):
		size = len(s)
		for x in range(1, size // 2 + 1):
			if size % x:
				continue
			if s[:x] * (size // x) == s:
				return True
		return False


class Solution:

	def repeatedSubstringPattern(self, s):
		n = len(s)
		for i in range(n // 2, 0, -1):
			if n % i == 0:
				repeat = s[0:i]
				if repeat * (n // i) == s:
					return True
		return False


class Solution:

	def repeatedSubstringPattern(self, s):
		if len(s) < 1:
			return True
		if len(s) == 1:
			return False
		for lenofsub in range(1, len(s)):
			if len(s) % lenofsub == 0:
				substring = [s[0:lenofsub]] * (len(s) // lenofsub)
				if ''.join(substring) == s:
					return True
		return False


class Solution:

	def repeatedSubstringPattern(self, s):
		ss = (s + s)[1:-1]
		return ss.find(s) != -1


class Solution:

	def repeatedSubstringPattern(self, s):
		s_len = len(s)
		for i in range(1, s_len // 2 + 1):
			if s[i] == s[0]:
				s_sub = s[:i]
				s_new = s_sub * (s_len // i)
				if s_new == s:
					return True
		return False


class Solution:

	def repeatedSubstringPattern(self, s):
		ss = (s * 2)[1:-1]
		return s in ss


class Solution:

	def repeatedSubstringPattern(self, s):
		length = len(s)
		base = 1
		while base <= length // 2:
			if length % base == 0:
				if s[:base] * (length // base) == s:
					return True
			base += 1
		return False