#-*- coding: UTF-8 -*-
#ZigZag Conversion :之字型
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows==1:return s
row=0
step=1
zigzag=['' for i in range(numRows)]
for c in s:
if row==0:step=1
if row==numRows-1:
step=-1
zigzag[row]+=c
row+=step
return "".join(zigzag)
sol=Solution()
print sol.convert("ABC", 2)
相关文章
- [LeetCode] 6. ZigZag Conversion 之字型转换字符串
- 《LeetBook》leetcode题解(6): ZigZag Conversion[E]
- 蜗牛慢慢爬 LeetCode 6. ZigZag Conversion [Difficulty: Medium]
- LeetCode 6 ZigZag Conversion(规律)
- Java [leetcode 6] ZigZag Conversion
- Leetcode 6. ZigZag Conversion(找规律,水题)
- LeetCode 6 ZigZag Conversion 模拟 难度:0
- 【LeetCode】6 - ZigZag Conversion
- 【leetcode❤python】 6. ZigZag Conversion
- Leetcode6--->Zigzag Conversion(将给定字符串按照Z字排列,输出结果)