class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
m = len(s)
n = 2*numRows - 2
s1 = ''
j = 0
i = 1
s1 += s[j]
flag = 0
if m == numRows:
flag = 1
if n>1 and flag == 0:
"""第一行加完"""
while (j+n)<m:
s1 += s[j+n]
j += n
"""除最后一行加完,规律:n-2i,2i,n-2i,2i"""
while i < (numRows-1):
j = i
flag = 1
while j<m:
s1 += s[j]
if flag == 1:
t = n-(2*i)
flag = 0
else:
t = (2*i)
flag = 1
j += t
i += 1
"""加上最后一行"""
j = i
while j<m:
s1 += s[j]
j += n
return s1
else:
return s