일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 밴픽
- Generator
- Class
- Python
- Protocol
- attribute
- 컴퓨터의 구조
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- Regular Expression
- shiba
- data science
- Python Implementation
- 43. Multiply Strings
- 715. Range Module
- Substring with Concatenation of All Words
- Python Code
- 프로그래머스
- t1
- 30. Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- kaggle
- 운영체제
- 시바견
- Convert Sorted List to Binary Search Tree
- concurrency
- DWG
- iterator
- 파이썬
- Decorator
Archives
- Today
- Total
Scribbling
LeetCode: 63. Unique Paths II 본문
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
n, m = len(obstacleGrid[0]), len(obstacleGrid)
board = [[0] * n for _ in range(m)]
board[0][0] = 1
obstacles = []
for i in range(m):
for j in range(n):
if obstacleGrid[i][j] == 1:
board[i][j] = 0
obstacles.append((i, j))
for j in range(1, n):
if (0, j) in obstacles:
continue
board[0][j] = board[0][j-1]
for i in range(1, m):
if (i, 0) in obstacles:
continue
board[i][0] = board[i-1][0]
for i in range(1, m):
for j in range(1, n):
if (i, j) in obstacles:
continue
board[i][j] = board[i-1][j] + board[i][j-1]
return board[m-1][n-1]
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 67. Add Binary (0) | 2021.09.26 |
---|---|
LeetCode: 64. Minimum Path Sum (0) | 2021.09.24 |
LeetCode: 62. Unique Paths (0) | 2021.09.24 |
LeetCode: 61. Rotate List (0) | 2021.09.24 |
LeetCode: 60. Permutation Sequence (0) | 2021.09.24 |