【每日一题202203010】重复的子串

:woman_mage:给定一个非空的字符串s,请编写一个函数,检查它是否可以通过由它的一个子串重复多次构成。

备注:s由纯小写英文字母组成;多次指大于等于2次。

示例:
输入:“abab”
输出:True
解释:可以由子串 “ab" 重复两次构成

题目难度:中等
题目来源:力扣 字符串 459

def solution(s: str) -> bool:
    # your code here

assert solution("abab") is True
assert solution("aba") is False
assert solution("abcabcabcabc") is True
assert solution("abaababaab") is True

def solution(astr):
flag = False
for i in range(1, int(len(astr)/2)+1):
tem = astr[0:i]
for j in range(1, len(astr)):
if tem*j == astr:
flag = True
else:
continue
return flag

def solution(s: str) -> bool:
    # 字符串s的长度
    l = len(s)
    # 遍历字符串,第1个字符,第1-2个字符,至字符串s一半长度
    # 如果字串 乘以 字符串l长度除以子串的长度 的乘积 等于字符串s,那么返回True
    # 否则,遍历完成后,返回False
    for i in range(int(l / 2)):
        if s[0:i + 1] * (int(l / (i + 1))) == s:
            return True
    return False


assert solution("abab") is True
assert solution("aba") is False
assert solution("abcabcabcabc") is True
assert solution("abaababaab") is True
def solution(s: str) -> bool:
    # your code here
    l = len(s)
    for i in range(0, l // 2):
        if s == s[0:i + 1] * (l // (i + 1)):
            return True
    return False
    def solution(s: str) -> bool:
        for i in range(len(s) // 2):
            if len(s) % (i + 1) == 0:
                if s[:i + 1] * (len(s) // (i + 1)) == s :
                    return True
        return False
import re


def solution(s: str) -> bool:
    # your code here
    for i in range(len(s)//2):
        list_s = re.findall('.{'+str(i+1)+'}', s)
        print(list_s)
        if list_s.count(list_s[0]) == len(list_s):
            return True
    return False


assert solution("abab") is True
assert solution("aba") is False
assert solution("abcabcabc") is True
assert solution("abaababaab") is True
def solution(s: str) -> bool:
    for i in range(len(s) - 1):
        res = ''.join(s.split(s[:i + 1]))
        if res == '':
            return True
    else:
        return False


assert solution("abab") is True
assert solution("aba") is False
assert solution("abcabcabcabc") is True
assert solution("abaababaab") is True