class Solution:
def convert(self, s: str, numRows: int) -> str:
if numRows == 1:
return s
length = len(s)
result = ""
for i in range(numRows): #一行行输出
step1 = 2*(numRows-1-i)
step2 = 2*i
pos = i #起始位置
if pos >= length:
break
result += s[pos]
while True:
pos += step1
if pos >= length: #直到pos越界
break
if step1: #step1不为0则输出
result += s[pos]
pos += step2
if pos >= length:
break
if step2:
result += s[pos]
return result