add new solutions
This commit is contained in:
parent
d798d5e8c9
commit
886b5e0a8e
34 changed files with 1164 additions and 0 deletions
27
solutions/0/q6/solution.go
Normal file
27
solutions/0/q6/solution.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue