diff --git a/leetcode/2075. Decode the Slanted Ciphertext/main.go b/leetcode/2075. Decode the Slanted Ciphertext/main.go new file mode 100644 index 0000000..2e840b3 --- /dev/null +++ b/leetcode/2075. Decode the Slanted Ciphertext/main.go @@ -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 +}