This commit is contained in:
VicRen
2020-11-24 09:00:01 +08:00
parent 6ac236008b
commit f645fead63
2 changed files with 59 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
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
}