6 ZigZag Conversion
Method: Store the information according to their layer. Use extra value to store the direction and the current layer value.
注意: 如果numRows == 1 没有必要进行conversion 这个情况单独列出来一下
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows == 1:
return s
d = [ "" for i in range(numRows)]
current_row = 0
current_direction = -1
for i in s:
print current_row
d[current_row] += i
if current_row == 0 or current_row == numRows - 1:
current_direction *= (-1)
current_row += current_direction
ans = ""
for i in d:
ans += i
return ans