62. Unique Paths (DP)
1 class Solution { 2 public int uniquePaths(int m, int n) { 3 int[][] res = new int[m][n]; 4 if(m == 0 || n == 0) return 0; 5 res[0][0] = 1; 6 for(int i = 0; i < m; i++) { 7 for(int j = 0; j < n; j++) { 8 if(i == 0 && j ==0) continue; 9 if(i - 1 < 0) { 10 res[i][j] = res[i][j - 1]; 11 }else if(j - 1 < 0) { 12 res[i][j] = res[i - 1][j]; 13 }else { 14 res[i][j] = res[i - 1][j] + res[i][j - 1]; 15 } 16 17 } 18 } 19 return res[m - 1][n - 1]; 20 } 21 }
没啥特别的