示例1:
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
示例2:
Python解决方案:
def convert(self, s, numRows):""":type s: str:type numRows: int:rtype: str"""if len(s) <= numRows or numRows==1 :return ss_dict = {i:"" for i in range(numRows)}unit = 2*numRows - 2for i in range(len(s)):remain = i%unitif remain <= numRows - 1:s_dict[remain] += s[i]else:pos = unit - remains_dict[pos] += s[i]out = ""for i in range(numRows):out += s_dict[i]return out