| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 사이드
- Problem Solving
- 뭐든
- 30분
- leetcode
- 3줄정리
- 프로젝트
- 영어공부
- 만화도
- 스탭퍼
- 미드시청
- 개발자
- 운동
- 영어원서읽기
- English
- Writing
- 매일
- 10분
- 파비최
- realclass
- 리얼 클래스
- 괜찮음
- FIT XR
- 읽기
- 화상영어
- 쓰릴오브파이트
- 잡생각
- 월간
- Daily Challenge
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/unique-paths-iii/description/
Unique Paths III - 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
DFS로 풀면 됨
class Solution:
def uniquePathsIII(self, grid: List[List[int]]) -> int:
m, n = range(len(grid)), range(len(grid[0]))
zeros = sum(row.count(0) for row in grid)
start = tuple((r, c) for r in m for c in n if grid[r][c] == 1)[0]
self.ans = 0
def dfs(row, col, zeros):
grid[row][col] = 3
for dr, dc in ((-1,0),(0,-1),(1,0),(0,1)):
R, C = row+dr, col+dc
if R in m and C in n:
if grid[R][C] == 0: dfs(R, C, zeros-1)
if grid[R][C] == 2 and zeros == 0: self.ans += 1
grid[row][col] = 0
return
dfs(*start, zeros)
return self.ans반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2023.01.02 |
|---|---|
| Today's Challenge (0) | 2023.01.01 |
| Today's Challenge (0) | 2022.12.30 |
| Today's Challenge (0) | 2022.12.29 |
| Today's Challenge (0) | 2022.12.28 |
Comments