Skip to content

Commit

Permalink
performance improvement by removing fmt. 22k ns/op -> 12k ns/op
Browse files Browse the repository at this point in the history
  • Loading branch information
vaskoz committed Sep 19, 2018
1 parent e19c112 commit fe087af
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions day29/problem.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package day29

import (
"fmt"
"strconv"
"strings"
)
Expand All @@ -19,12 +18,14 @@ func RunLengthEncoding(str string) string {
} else if r == last {
count++
} else {
sb.WriteString(fmt.Sprintf("%d%s", count, string(last)))
sb.WriteString(strconv.Itoa(count))
sb.WriteString(string(last))
count = 1
last = r
}
}
sb.WriteString(fmt.Sprintf("%d%s", count, string(last)))
sb.WriteString(strconv.Itoa(count))
sb.WriteString(string(last))
return sb.String()
}

Expand Down

0 comments on commit fe087af

Please sign in to comment.