当前位置:网站首页>【LeetCode】64. 最小路径和
【LeetCode】64. 最小路径和
2022-06-10 01:08:00 【LawsonAbs】
0.总结
- 简单dp题
1.题目
2.思想
根据数据规模,可以看到本题需要使用dp
(1)dp[i][j] 表示到 坐标[i,j] 的最小路径和
(2)递推公式: dp[i][j] = min(dp[i][j-1],dp[i-1][j]) + grid[i][j]
3.代码
class Solution:
def minPathSum(self, grid: List[List[int]]) -> int:
m,n = len(grid),len(grid[0])
# 补充最后一行 + 一列
dp = [[9999 for i in range(n+1)] for j in range(m+1)]
for i in range(m):
for j in range(n):
if i == 0 and j == 0:
dp[0][0] = grid[0][0]
continue
dp[i][j] = min(dp[i][j-1],dp[i-1][j]) + grid[i][j]
# print(dp)
return dp[m-1][n-1]
边栏推荐
- Application of discrete time integration in Simulink simulation
- H3C IRF configuration example
- 洛谷P1220 关路灯 题解 区间DP
- Mysql——》查看索引的大小
- JVM——》类文件
- Shell exec and i/o redirection
- Think of GPL as a "virus"? Please stop defaming GPL
- Shell Eval usage explanation command replacement
- Random talk on test coverage
- 总结——》【JVM】
猜你喜欢

Maui + MVVM + Siemens cross platform application practice

Mongodb open source "queryable encryption" system
Beyond Compare 3密钥序列号分享及密钥被撤销的解决办法

Win11怎么直接退回进入桌面?

Why do programmers run away after two years?

【ICLR 2022】Towards Continual Knowledge Learning of Language Models

Mysql——》事务的隔离级别

把 GPL 视作“病毒”?请停止污名化 GPL

Web3 is crucial to the data sovereignty of the meta universe

别再重复造轮子了,推荐使用 Google Guava 开源工具类库,真心强大!
随机推荐
Regular expression does not contain a string
洛谷P1220 关路灯 题解 区间DP
Associative array & regular expression
JVM records a CPU surge
datagrip的两个问题
从转载阿里开源项目 Egg.js 技术文档引发的“版权纠纷”,看宽松的 MIT 许可该如何用?
shell xxx. sh: line 284: return: -1: invalid option
How can I right-click win11 to open all options directly?
Way home
Summary - 【 JVM 】
MySQL - separate database and table
JVM——》类文件
Unity technology - 2D project experience
Mongodb open source "queryable encryption" system
孙宇晨等收购Poloniex,公链交易所双轮驱动波场生态
Win11怎么直接退回进入桌面?
騰訊Libco協程開源庫 源碼分析(一)---- 下載Libco 編譯安裝 嘗試運行示例代碼
Shell Eval usage explanation command replacement
洛谷P1029 最大公约数和最小公倍数问题 题解
LEAK: ByteBuf.release() was not called before it‘s garbage-collected