版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412983
有一个神奇的解法:
func repeatedSubstringPattern(s string) bool {
str := []byte(s)
if len(str) <= 1 {
return false
}
max := len(str) / 2
for i := 1; i <= max; i++ {
j := i
idx := 0
if len(str)%i > 0 {
continue
}
for ; j < len(str); j++ {
if str[j] != str[idx] {
break
}
idx++
if idx >= i {
idx = 0
}
}
if j == len(str) {
return true
}
}
return false
}