赞
踩
1.题目
2.解法
①二维数组+动态规划
- class Solution {
- public int uniquePaths(int m, int n) {
- if(n == 0) return 0;
- int[][] dp = new int[m][n];
- dp[0][0] = 1;
- for(int i = 0; i < m; i++){
- for(int j = 0; j < n; j++){
- if(i == 0 && j != 0) dp[i][j] = dp[i][j - 1];
- else if(j == 0 && i != 0) dp[i][j] = dp[i - 1][j];
- else{
- if(i != 0 && j != 0) dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
- }
- }
- }
- return dp[m - 1][n - 1];
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。