给定一个字符串,请你判断这个字符串是否可以通过重复多次它的子字符串来构成。
数据范围:字符串长度 ,保证字符串中仅包含小写英文字母
import java.util.*; public class Solution { public boolean repeatSubstring (String str) { return (str + str).substring(1, str.length() * 2 - 1).contains(str); } }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @return bool布尔型 # class Solution: def repeatSubstring(self , str: str) -> bool: # write code here for i in range(1, len(str)): if len(str) % i != 0: continue if not str.replace(str[:i], ''): return True return False