mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 19:54:43 +01:00
28 lines
353 B
Go
28 lines
353 B
Go
package main
|
|
|
|
import "strconv"
|
|
|
|
func main() {
|
|
|
|
}
|
|
|
|
func compress(str string) string {
|
|
var cl int32
|
|
count := 0
|
|
var ret string
|
|
for _, s := range str {
|
|
if s != cl {
|
|
cl = s
|
|
count = 1
|
|
ret += string(s) + "1"
|
|
} else {
|
|
count++
|
|
ret = ret[:len(ret)-1] + strconv.Itoa(count)
|
|
}
|
|
if len(ret) >= len(str) {
|
|
return str
|
|
}
|
|
}
|
|
return ret
|
|
}
|