当前位置:网站首页>leetcode 62. Unique Paths(独特的路径)
leetcode 62. Unique Paths(独特的路径)
2022-08-02 09:17:00 【蓝羽飞鸟】
出发点在左上角,目的地在右下角,问从出发点到目的地有多少不同的路径。
思路:
典型的DP
dp[i][j]表示到达(i, j)处有多少条不同的路径。
第1行和第一列显然只有一条路径。
然后因为只能向右和向下运动,所以dp[i][j]来自于它上方和左方的路径个数
dp[i][j] = dp[i-1][j] + dp[i][j-1]
public int uniquePaths(int m, int n) {
int[][] dp = new int[m][n];
for(int i = 0; i < m; i++) dp[i][0] = 1;
for(int j = 0; j < n; j++) dp[0][j] = 1;
for(int i = 1; i < m; i++) {
for(int j = 1; j < n; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[m-1][n-1];
}
边栏推荐
猜你喜欢
不用Swagger,那我用啥?
百数应用中心——选择一款适合企业的标准应用
AutoJs学习-存款计算器
【微信小程序2】事件绑定
Scala类型转换
system_error错误处理库学习
百战RHCE(第四十七战:运维工程师必会技-Ansible学习2-Ansible安装配置练习环境)
Tencent T8 architect, teach you to learn small and medium R&D team architecture practice PDF, senior architect shortcut
Talk about the understanding of Volatile
shell脚本
随机推荐
智能网络安全网卡|这是不是你要的安全感
UVM信息服务机制
js函数防抖和函数节流及其使用场景
Jenkins--基础--5.4--系统配置--全局工具配置
PyCharm usage tutorial (detailed version - graphic and text combination)
裁员趋势下的大厂面试:“字节跳动”
[Must read] Mylander valuation analysis, electrical stimulation products for pelvic and postpartum rehabilitation
记某社区问答
AlterNET Studio用户界面设计功能扩展
Have you ever learned about these architecture designs and architecture knowledge systems?(Architecture book recommendation)
Talk about the understanding of Volatile
day——05 迭代器,生成器
A little bit of knowledge - why do not usually cook with copper pots
sql concat(),如何才能拼接表的名字
PyQt5安装配置(PyCharm) 亲测可用
postman下载安装汉化及使用
【微信小程序】本地服务页面案例实现
What is the function of the import command of the page directive in JSP?
动态规划每日一练(2)
破解wifi密码 暴力破解 保姆式教学