62:不同路径
This commit is contained in:
parent
3a0d70ee93
commit
a957bc7a6b
@ -64,8 +64,19 @@ public class UniquePaths {
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public int uniquePaths(int m, int n) {
|
||||
int max = Math.max(m, n);
|
||||
return max * (max + 1) / 2;
|
||||
int[][] f = new int[m][n];
|
||||
for (int i = 0; i < m; ++i) {
|
||||
f[i][0] = 1;
|
||||
}
|
||||
for (int j = 0; j < n; ++j) {
|
||||
f[0][j] = 1;
|
||||
}
|
||||
for (int i = 1; i < m; ++i) {
|
||||
for (int j = 1; j < n; ++j) {
|
||||
f[i][j] = f[i - 1][j] + f[i][j - 1];
|
||||
}
|
||||
}
|
||||
return f[m - 1][n - 1];
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user