class Solution(object): def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str """ if numRows == 1: return s elif len(s) == 0: return "" res = [''] * numRows for i in range(len(s)): ans = i // (numRows - 1) cur = i % (numRows - 1) if ans % 2 == 0: res[cur] += s[i] else: res[numRows-cur-1] += s[i] return ''.join(res)