일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- FIT XR
- 3줄정리
- 월간
- 리얼 클래스
- 스탭퍼
- 매일
- Writing
- 쓰릴오브파이트
- 개발자
- English
- 운동
- 프로젝트
- 영어원서읽기
- 영어공부
- 사이드
- 파비최
- 30분
- leetcode
- 링피트
- realclass
- 10분
- 읽기
- 미드시청
- 뭐든
- Problem Solving
- 괜찮음
- 잡생각
- 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