Skip to content
Open

2075 #63

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions leetcode/2075. Decode the Slanted Ciphertext/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import "strings"

func decodeCiphertext(encodedText string, rows int) string {
if rows == 0 {
return ""
}

var (
n = len(encodedText)
cols = n / rows
sb strings.Builder
)

for idx := range cols {
r, c := 0, idx

for r < rows && c < cols {
sb.WriteByte(encodedText[r*cols+c])

r += 1
c += 1
}
}

result := strings.TrimRight(sb.String(), " ")

return result
}