class Solution:
def convert(self, s: str, numRows: int) -> str:
string = ''
edge = 2*(numRows-1)
if edge == 0 or len(s) <= numRows:
return s
cut = []
while len(s) > edge:
cut.append(s[:edge])
s = s[edge:]
cut.append(s)
length = 0
for c in cut:
string += c[0]
print(edge)
for i in range(1,numRows-1):
for c in cut:
if len(c) > i:
string += c[i]
if len(c) > edge-i:
string += c[edge-i]
for c in cut:
if len(c) > edge/2:
string += c[int(edge/2)]
return string
github项目地址:https://github.com/JockWang/LeetCode-Python