我试图解决以下问题:
字符串“PAYPALISHIRING”在给定的行数上以锯齿形模式写入,如下所示:(您可能希望以固定字体显示此模式,以提高可读性)P A H N
A P L S I I G
Y I R
然后一行一行地读:“pahnaplshigyir”
编写将接受字符串的代码,并在给定行数的情况下进行此转换:
字符串转换(字符串s,int numRows)
我已经写了下面的代码,但是粗体部分有错误
“TypeError:不支持+:'NoneType'和'unicode'的操作数类型”class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows==1:
return s
templist=[None]*numRows
ret=" "
curRow=0
goingDown=0
for each_char in s:
if templist[curRow]:
templist[curRow]=each_char
else:
**templist[curRow]=templist[curRow] + each_char**
if (curRow==numRow-1 or curRow == 0):
goingDown = not goingDown
if goingDown:
curRow=curRow+1
else:
curRow=curRow-1
for each_str in templist:
ret=ret+each_str
print ret
我在这方面做错了什么吗。如果有人能在这里指出问题,那就太好了。
提前谢谢