[LeetCode][Python3] 174. Dungeon Game
2019. 8. 28. 00:06 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/dungeon-game/
My Solution :
class Solution:
def calculateMinimumHP(self, dungeon):
M, N = len(dungeon), len(dungeon[0])
HP = [[float('INF')]*(N+1) for _ in range(M+1)]
HP[M][N-1] = HP[M-1][N] = 1
for r in range(M-1, -1, -1):
for c in range(N-1, -1, -1):
need = min(HP[r+1][c], HP[r][c+1]) - dungeon[r][c]
HP[r][c] = need if need > 1 else 1
return HP[0][0]
Comment :
도착점부터 거꾸로 시작점까지 올라가며 계산하는 DP 문제
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 692. Top K Frequent Words (0) | 2019.09.03 |
---|---|
[LeetCode][Python3] 89. Gray Code (0) | 2019.09.03 |
[LeetCode][Python3] 357. Count Numbers with Unique Digits (0) | 2019.08.29 |
[LeetCode][Python3] 996. Number of Squareful Arrays (0) | 2019.08.28 |
[LeetCode][Python3] 77. Combinations (0) | 2019.08.25 |
[LeetCode][Python3] 39. Combination Sum (0) | 2019.08.23 |
[LeetCode][Python3] 216. Combination Sum III (0) | 2019.08.23 |
[LeetCode][Python3] 52. N-Queens II (0) | 2019.08.23 |
최근에 달린 댓글 최근에 달린 댓글