Input: s = "abab"
Output:
true
Explanation:
It is the substring "ab" twice.
Input: s = "aba"
Output:
false
Input: s = "abcabcabcabc"
Output:
true
Explanation:
It is the substring "abc" four times or the substring "abcabc" twice.
func repeatedSubstringPattern(s string) bool {
length := len(s)
for i:=0; i<len(s)-1; i++ {
if length%(i+1)==0 {
if check(s, i+1) {
return true
}
}
}
return false
}
func check(s string, l int) bool {
for i:=0; i<l; i++ {
for j:=i; j<len(s); j = j+l {
if s[j]!=s[i] {
return false
}
}
}
return true
}g
func repeatedSubstringPattern(s string) bool {
l := len(s)
for i:=1; i<=l/2; i++ {
if l%i == 0 {
var str strings.Builder
str.WriteString(s[:i])
for len(str.String()) < l {
str.WriteString(s[:i])
}
if str.String() == s {
return true
}
}
}
return false
}
func repeatedSubstringPattern(s string) bool {
l := len(s)
for i := 1; i <= l/2; i++ {
if l%i == 0 && strings.Repeat(string(s[:i]), l/i) == s {
return true
}
}
return false
}