forked from nyabokegrace/checkpoints
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzipstring.go
More file actions
44 lines (35 loc) · 821 Bytes
/
Copy pathzipstring.go
File metadata and controls
44 lines (35 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
)
func ZipString(s string) string {
if len(s) == 0 {
return ""
}
result := ""
count := 1
for i := 1; i <= len(s); i++ {
// trigger flush when reaching end OR character changes
if i == len(s) || s[i] != s[i-1] {
tmp := count
digits := ""
if tmp == 0 {
digits = "0"
} else {
for tmp > 0 {
digits = string(rune('0'+(tmp%10))) + digits
tmp /= 10
}
}
result += digits
result += string(s[i-1])
count = 1
} else {
count++
}
}
return result
}
func main() {
fmt.Println(ZipString("aaaaaaaaaaaaaaaqqwedeeetrtrrgghaghhyy"))
}