当前位置:网站首页>leetcode:6. Zigzag transformation

leetcode:6. Zigzag transformation

2022-06-12 01:47:00 Review of the white speed Dragon King

 Insert picture description here
Ideas :
Simple simulation , Pay attention to special situations numsrow = 1

src:

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        len1 = len(s)
        cnt = 0
        i = 0
        flag = "down"
        lists = [[] for i in range(numRows)]# Establishment of two-dimensional array 
        while cnt < len1:
            lists[i].append(s[cnt])
            cnt += 1
            # Special treatment 
            if numRows == 1:
                continue
            if i == 0:
                flag = "down"
            if i == numRows - 1:
                flag = "up"
            if flag == "down":
                i += 1
            else:
                i -= 1
        res = ""
        for i in range(numRows):
            res += "".join(lists[i])
        return res

summary :
Simple simulation is enough

原网站

版权声明
本文为[Review of the white speed Dragon King]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011215436749.html