add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 9a10695e8c
commit ca24d0a56a
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
30 changed files with 697 additions and 16 deletions

View file

@ -0,0 +1,28 @@
package q1071
func isRepeatOf(segment, str string) bool {
if len(segment) > len(str) || len(segment) == 0 || len(str)%len(segment) != 0 {
return false
}
for len(str) > 0 {
if str[:len(segment)] != segment {
return false
}
str = str[len(segment):]
}
return true
}
func gcdOfStrings(str1 string, str2 string) string {
if len(str1) > len(str2) {
str1, str2 = str2, str1
}
for l := len(str1); l > 0; l-- {
if isRepeatOf(str1[:l], str1) && isRepeatOf(str1[:l], str2) {
return str1[:l]
}
}
return ""
}
var _ = gcdOfStrings