[LeetCode][Python3] 980. Unique Paths III
2019. 8. 20. 00:01 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/unique-paths-iii/
My Solution :
class Solution:
def uniquePathsIII(self, grid):
def dfs(r, c, remain):
if grid[r][c] == 2:
if remain == 0:
self.ans += 1
return
grid[r][c] = -1
for y, x in ((r+1, c), (r-1, c), (r, c+1), (r, c-1)):
if (0 <= y < len(grid) and
0 <= x < len(grid[0]) and
grid[y][x] in (0, 2)):
dfs(y, x, remain-1)
grid[r][c] = 0
self.ans = 0
remain = 0
for r in range(len(grid)):
for c in range(len(grid[0])):
if grid[r][c] in (0, 1):
remain += 1
if grid[r][c] == 1:
R, C = r, c
dfs(R, C, remain)
return self.ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 216. Combination Sum III (0) | 2019.08.23 |
---|---|
[LeetCode][Python3] 52. N-Queens II (0) | 2019.08.23 |
[LeetCode][Python3] 526. Beautiful Arrangement (0) | 2019.08.21 |
[LeetCode][Python3] 784. Letter Case Permutation (0) | 2019.08.20 |
[LeetCode][Python3] 47. Permutations II (0) | 2019.08.18 |
[LeetCode][Python3] 1079. Letter Tile Possibilities (0) | 2019.08.16 |
[LeetCode][Python3] 765. Couples Holding Hands (0) | 2019.08.15 |
[LeetCode][Python3] 854. K-Similar Strings (0) | 2019.08.15 |
최근에 달린 댓글 최근에 달린 댓글