ZigZag Conversion


The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this

P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:
string convert(string s, int numRows);

Example 1:
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
Example 2:
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:

P     I    N
A   L S  I G
Y A   H R
P     I
Solution:
class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if numRows == 1:
            return s
        data = [['' for _ in range(len(s))] for _ in range(numRows)]
        row, col = (0, 0)
        is_descending = True

        for letter in s:
            data[row][col] = letter
            if is_descending:
                if row == numRows - 1:
                    is_descending = False
                    row, col = (row - 1, col + 1)
                    continue
                row += 1
            else:
                if row == 0:
                    is_descending = True
                    row += 1
                    continue
                row, col = (row - 1, col + 1)
        return ''.join([''.join(row).replace(' ', '') for row in data])