Commit d627e4bf by bonnieyan

提交第四次作业

parent cfb70698
#z字形变换
'''
L C I R
E T O E S I I G
E D H N
'''
def convert(s, numRows):
rows = [''] * numRows
#必须为False,否则数据越界,本来角标为len-1
isInc = False
curro = 0
for c in s:
rows[curro] += c
if curro == 0 or curro == numRows - 1:
isInc = not isInc
if isInc:
curro += 1
else:
curro -= 1
return ''.join(rows)
print(convert("LEETCODEISHIRING",4))
print(convert("LEETCODEISHIRING",3))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment