2075. Decode the Slanted Ciphertext

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2075

class Solution:
    def decodeCiphertext(self, encodedText: str, rows: int) -> str:
        res = []
        cols = len(encodedText) // rows
        for j in range(cols):
            x, y = 0, j
            while x < rows and y < cols:
                res.append(encodedText[x * cols + y])
                x, y = x + 1, y + 1
        return ''.join(res).rstrip()