add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
28
solutions/10/q1071/solution.go
Normal file
28
solutions/10/q1071/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue