| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- 10분
- 월간
- 만화도
- 리얼 클래스
- Writing
- 사이드
- 잡생각
- 미드시청
- 운동
- 링피트
- realclass
- 쓰릴오브파이트
- 뭐든
- 파비최
- 읽기
- 영어공부
- 영어원서읽기
- Problem Solving
- 스탭퍼
- 괜찮음
- 프로젝트
- leetcode
- English
- 화상영어
- 매일
- 30분
- 개발자
- 3줄정리
- Daily Challenge
- FIT XR
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.01.24 Today's Challenge 본문
https://leetcode.com/problems/snakes-and-ladders/
Snakes and Ladders - LeetCode
Snakes and Ladders - You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style [https://en.wikipedia.org/wiki/Boustrophedon] starting from the bottom left of the board (i.e. board[n - 1][0]) and alternati
leetcode.com
아예 감도 안잡힘 =_= 너무 오랫만에 풀어보려고 시도했음
class Solution:
def snakesAndLadders(self, board: List[List[int]]) -> int:
board.reverse()
for i in range(1, len(board), 2):
board[i].reverse()
ar = [None] + list(chain(*board))
n, qu, seen, ct = len(ar) - 1, deque([1]), {1}, 0
while qu:
len_q = len(qu)
for _ in range(len_q):
cur = qu.popleft()
if cur == n:
return ct
for i in range(cur+1, min(cur+7, n+1)):
nxt = ar[i] if ar[i] + 1 else i
if nxt in seen:
continue
seen.add(nxt)
qu.append(nxt)
ct += 1
return -1반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.01.26 Today's Challenge (0) | 2023.01.26 |
|---|---|
| 2023.01.25 Today's Challenge (0) | 2023.01.25 |
| 2023.01.23 Today's Challenge (0) | 2023.01.23 |
| 2023.01.22 Today's Challenge (0) | 2023.01.22 |
| 2023.01.21 Today's Challenge (0) | 2023.01.21 |
Comments