(chars []byte)
| 3 | import "fmt" |
| 4 | |
| 5 | func compress(chars []byte) int { |
| 6 | if len(chars) == 0 { |
| 7 | return 0 |
| 8 | } |
| 9 | start := 0 |
| 10 | end := 0 |
| 11 | pivot := 0 |
| 12 | for i := 1; i < len(chars); i++ { |
| 13 | if chars[i] != chars[i-1] { |
| 14 | chars[pivot] = chars[start] |
| 15 | pivot++ |
| 16 | if start != end { |
| 17 | for _, x := range fmt.Sprint(end - start + 1) { |
| 18 | chars[pivot] = byte(x) |
| 19 | pivot++ |
| 20 | } |
| 21 | } |
| 22 | start = i |
| 23 | } |
| 24 | end = i |
| 25 | } |
| 26 | chars[pivot] = chars[start] |
| 27 | pivot++ |
| 28 | if start != end { |
| 29 | for _, x := range fmt.Sprint(end - start + 1) { |
| 30 | chars[pivot] = byte(x) |
| 31 | pivot++ |
| 32 | } |
| 33 | } |
| 34 | start = i |
| 35 | return pivot |
| 36 | } |
nothing calls this directly
no outgoing calls
no test coverage detected