파비의 매일매일 공부기록

2023.02.03 Today's Challenge 본문

Problem Solving/LeetCode

2023.02.03 Today's Challenge

fabichoi 2023. 2. 3. 23:45

https://leetcode.com/problems/zigzag-conversion/

 

Zigzag Conversion - LeetCode

Zigzag Conversion - The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAP

leetcode.com

세로와 가로를 바꿔서 출력!

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        rr = range(numRows)
        pattern = list(rr) + list(range(numRows-2, 0, -1))
        times = math.ceil(len(s)/len(pattern))
        patterns = pattern*times

        arr = ["" for _ in rr]

        for a, b in zip(patterns, s):
            arr[a] += b
        
        return "".join(arr)
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.02.05 Today's Challenge  (0) 2023.02.05
2023.02.04 Today's Challenge  (0) 2023.02.04
2023.02.02 Today's Challenge  (0) 2023.02.02
2023.02.01 Today's Challenge  (0) 2023.02.01
2023.01.31 Today's Challenge  (0) 2023.01.31
Comments