27 lines
491 B
Go
27 lines
491 B
Go
package q6
|
|
|
|
import "strings"
|
|
|
|
func convert(s string, numRows int) string {
|
|
loopLen := numRows + max(0, numRows-2)
|
|
rows := make([][]byte, numRows)
|
|
for i := range numRows {
|
|
rows[i] = make([]byte, 0, (len(s)/loopLen+1)*2)
|
|
}
|
|
|
|
for i := range len(s) {
|
|
row := i % loopLen
|
|
if row >= numRows {
|
|
row = numRows - row%numRows - 2
|
|
}
|
|
rows[row] = append(rows[row], s[i])
|
|
}
|
|
|
|
b := strings.Builder{}
|
|
for i := range rows {
|
|
_, _ = b.Write(rows[i])
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
var _ = convert
|