일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 읽기
- 사이드
- Writing
- 영어원서읽기
- 링피트
- 30분
- English
- 리얼 클래스
- Daily Challenge
- leetcode
- 뭐든
- realclass
- 잡생각
- 매일
- 월간
- 미드시청
- 파비최
- 개발자
- Problem Solving
- 영어공부
- 스탭퍼
- 프로젝트
- FIT XR
- 괜찮음
- 화상영어
- 쓰릴오브파이트
- 운동
- 3줄정리
- 10분
- 만화도
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination/
Shortest Path in a Grid with Obstacles Elimination - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
최단거리?! 와우....
일단 풀기전에 포긔s..
class Solution:
def shortestPath(self, grid: List[List[int]], k: int) -> int:
m, n = len(grid), len(grid[0])
if k >= m + n -2:
return m + n - 2
dq = deque([(0, 0, k, 0)])
visited = set()
while dq:
i, j, k, s = dq.popleft()
if (i, j) == (m-1, n-1):
return s
for ii, jj in [(i+1,j), (i-1,j), (i, j+1), (i, j-1)]:
if 0 <= ii < m and 0 <= jj <n and k >= grid[ii][jj]:
step = (ii, jj, k-grid[ii][jj], s+1)
if step[0:3] not in visited:
visited.add(step[0:3])
dq.append(step)
return -1
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.11.01 |
---|---|
Today's Challenge (0) | 2022.10.31 |
Today's Challenge (0) | 2022.10.29 |
Today's Challenge (0) | 2022.10.28 |
Today's Challenge (0) | 2022.10.27 |
Comments