class Solution:
def convert(self, s: str, numRows: int) -> str:
n,r = len(s),numRows
# 直接返回当前字符
if r == 1 or n <= r:
return s
# 计算周期大小
t = 2*r - 2
c = (n + t - 1) // t * (r - 1)
# 构造位置矩阵
arr = [['' for _ in range(c)] for _ in range(r)]
x = 0
y = 0
for i,c in enumerate(s):
arr[x][y] = c
if i % t < r - 1:
x += 1
else:
x -= 1
y += 1
return ''.join([c for line in arr for c in line])