LeetCode: Unique Paths 解题报告
2015-04-08 02:38
387 查看
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
View Code
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
public class Solution { public int uniquePaths(int m, int n) { if (m <= 0 || n <= 0) { return 0; } int[][] D = new int[m] ; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (i == 0 && j == 0) { D[i][j] = 1; } else if (i == 0) { D[i][j] = D[i][j - 1]; } else if (j == 0) { D[i][j] = D[i - 1][j]; } else { D[i][j] = D[i - 1][j] + D[i][j - 1]; } } } return D[m - 1][n - 1]; } }
View Code
相关文章推荐
- [LeetCode] Unique Paths 解题报告
- LeetCode 62 Unique Paths 解题报告
- 【LeetCode】Unique Paths 解题报告
- [LeetCode] Unique Paths 解题报告
- LeetCode 19. Remove Nth Node From End of List 解题报告
- [Leetcode] 720. Longest Word in Dictionary 解题报告
- LeetCode ZigZag Conversion 解题报告
- (待解决)LeetCode 10. Regular Expression Matching 解题报告
- [leetcode] 63. Unique Paths II 解题报告
- leetcode解题报告:45. Jump Game II
- leetcode解题报告-342. Power of Four
- Leetcode 399 python 解题报告
- 【LeetCode】189.Rotate Array(Easy)解题报告
- [leetcode] 238. Product of Array Except Self 解题报告
- [leetcode] 32. Longest Valid Parentheses 解题报告
- [leetcode] 358. Rearrange String k Distance Apart 解题报告
- 【LeetCode】75.Sort Colors(Medium)解题报告
- 3Sum LeetCode 解题报告
- LeetCode: Balanced Binary Tree 解题报告
- 【LeetCode】729. My Calendar I 解题报告