| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- 스탭퍼
- 쓰릴오브파이트
- leetcode
- 10분
- realclass
- 괜찮음
- English
- 영어원서읽기
- 3줄정리
- Problem Solving
- 월간
- 화상영어
- 잡생각
- 파비최
- 프로젝트
- 개발자
- 뭐든
- Writing
- 매일
- 읽기
- 리얼 클래스
- 30분
- 사이드
- Daily Challenge
- 운동
- 만화도
- 영어공부
- FIT XR
- 링피트
- 미드시청
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.03 Today's Challenge 본문
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