LeetCode#62. Unique Paths
来源:互联网 发布:虎扑认证淘宝店铺 编辑:程序博客网 时间:2024/06/05 22:45
- 题目:一个m*n的数组,求从左上角到右下角的路径总数
- 难度:Medium
- 思路:第一行和第一列位置对应的result的值都是1,除第一行和第一列之前的其他位置等于该位置的上边和左边位置之和
- 代码:
public class Solution { public int uniquePaths(int m, int n) { if(m == 1 || n == 1){ return 1; } int[][] result = new int[m][n]; result[0][0] = 0; 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 >0 && j >0){ result[i][j] = result[i][j-1] + result[i-1][j]; } } } 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
- 代码Python入门(五、循环语句(一))
- 排序算法的性能问题
- jQuery 选择器
- Java--BigInteger类型
- C++抽象编程——接口(2)——接口的用途
- LeetCode#62. Unique Paths
- RDIFramework.NET平台代码生成器V3.2版本全新发布-更新于2017-02-27(提供下载-免费使用)[申明:来源于网络]
- LeetCode 5. Longest Palindromic Substring 解题报告
- StartService返回值为2
- bzoj2679 [Usaco2012 Open]Balanced Cow Subsets折半搜索
- webpack进阶构建项目(一)
- 剑指offer(C++)——矩阵覆盖
- [JZOJ5086]数列
- softmax分类器 python实现