최대 1 분 소요

Python

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if len(s) <= numRows or numRows < 2:
            return s

        current = 0
        num = 2 * (numRows - 1)
        answer = [""] * numRows
        for i in range(len(s)):
            current = i % num
            if current < numRows:
                answer[current] += s[i]
            else:
                answer[num - current] += s[i]
                
        return ''.join(answer)

댓글남기기