Dungeon Game
来源:互联网 发布:淘宝店主真人内衣展示 编辑:程序博客网 时间:2024/06/04 19:18
https://leetcode.com/problems/dungeon-game/
public class Solution { public int calculateMinimumHP(int[][] dungeon) { if (dungeon == null || dungeon.length == 0 || dungeon[0].length == 0) return 0; int m = dungeon.length; int n = dungeon[0].length; int[][] health = new int[m][n]; health[m - 1][n - 1] = Math.max(1 - dungeon[m - 1][n - 1], 1); for (int i = m - 2; i >= 0; i--) { health[i][n - 1] = Math.max(health[i + 1][n - 1] - dungeon[i][n - 1], 1); } for (int j = n - 2; j >= 0; j--) { health[m - 1][j] = Math.max(health[m - 1][j + 1] - dungeon[m - 1][j], 1); } for (int i = m - 2; i >= 0; i--) { for (int j = n - 2; j >= 0; j--) { int down = Math.max(health[i + 1][j] - dungeon[i][j], 1); int right = Math.max(health[i][j + 1] - dungeon[i][j], 1); health[i][j] = Math.min(right, down); } } return health[0][0]; }}
0 0
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- Dungeon Game
- gcc与g++的区别
- Shortest Palindrome
- Android Api Demos登顶之路(八十五)Graphics-->PurgeableBitmap
- Expression Add Operators
- 注册和登录的测试服务器搭建
- Dungeon Game
- Minimum Window Substring
- Best Time to Buy and Sell Stock IV
- Adaboost 算法的原理与推导
- *LeetCode-Largest Number
- Regular Expression Matching
- QSqlDatabase类
- QSqlQuery类
- Candy