1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/greatest-common-divisor-of-strings.go

18 lines
253 B
Go
Raw Normal View History

package main
func gcdOfStrings(str1 string, str2 string) string {
gcd := func(x, y int) int {
for y != 0 {
x, y = y, x%y
}
return x
}
if str1+str2 != str2+str1 {
return ""
}
length := gcd(len(str1), len(str2))
return str1[:length]
}