LeetCode#62. Unique Paths
来源:互联网 发布:手机版施工软件 编辑:程序博客网 时间:2024/06/06 01:56
- 题目:给定一个m*n的数组,从最左上角到最右下角的路径数(每次只能往右或者往下)
- 难度:Medium
- 思路:定义一个m*n的数组来存储从最左上角到第i行第j列那个单元格的路径数(初始化:数组的第0行第0列初始为0,第0行的其他元素为1,第0列的其他元素为1,然后其他行列的值等它的上和左的路径数之和)
- 代码:
public class Solution { public int uniquePaths(int m, int n) { int[][] result = new int[m][n]; result[0][0] = 0; if(m == 1 || n == 1){ return 1; } for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ if(i == 0 && j != 0){ result[i][j] = 1; } if(j == 0 && i != 0){ result[i][j] = 1; } if(i >= 1 && j >= 1){ result[i][j] = result[i-1][j] + result[i][j-1]; } } } return result[m-1][n-1]; }}
0 0
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- [Leetcode] 62. Unique Paths
- [leetcode] 62.Unique Paths
- [leetcode] 62.Unique Paths
- leetcode 62. Unique Paths
- Leetcode 62. Unique Paths
- [leetcode] 62. Unique Paths
- 62. Unique Paths LeetCode
- [LeetCode]62. Unique Paths
- 【LeetCOde】62. Unique Paths
- [LeetCode]62. Unique Paths
- leetcode 62. Unique Paths
- LeetCode 62. Unique Paths
- LeetCode *** 62. Unique Paths
- leetcode 62. Unique Paths
- Leetcode:62. Unique Paths
- javascript书籍
- 一键解决80端口被占用
- 功能点方法概述
- CodeForces 681A A Good Contest
- QT中的setGeometry (9, 9, 50, 25) 四个参数分别是指什么?
- LeetCode#62. Unique Paths
- poj3468 A Simple Problem with Integers(用线段树和树状数组实现)
- 九、FatMouse' Trade
- 理解进程调度时机跟踪分析进程调度与进程切换的过程
- 使用MultiDex解决65535限制问题
- STL----iterator 迭代器
- More is Less——卷积网络加速
- Java类的访问权限
- RecyclerView自定义分割线————列表分割线