题目
个人见解
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
Pass=0
j=0
data=list(s)
length=len(data)
if length<2 or numRows==1:
return s
x=[[False for _ in range((length//(2*numRows-2)+1)*(numRows-1))] for _ in range(numRows)]
for i in range(length):
local=i%(2*numRows-2)
bolk=i//(2*numRows-2)
if bolk!=Pass:
Pass=bolk
j=0
if local<numRows:
x[local][bolk*(numRows-1)]=data[i]
else:
j+=1
x[numRows-j-1][bolk*(numRows-1)+j]=data[i]
strr=''
for i in range(numRows):
for j in range((length//(2*numRows-2)+1)*(numRows-1)):
if x[i][j]!=False:
strr+=x[i][j]
return strr
通过数学关系找出了下标的位置,然后填表矩阵,最后遍历矩阵输出,
然而,结果惨不忍睹
(咋好意思炫耀。。。。。。。。。)
引用评论席的一句:看完题解觉得自己是智障。
题解在此
权限&免责&交流声明