题解 | #不同路径的数目(一)#
不同路径的数目(一)
http://www.nowcoder.com/practice/166eaff8439d4cd898e3ba933fbc6358
import java.util.*;
public class Solution {
/**
*
* @param m int整型
* @param n int整型
* @return int整型
*/
public int uniquePaths (int m, int n) {
// write code here
int[][] dp = new int[n][m];
for (int i = 0; i < n; i++) {
dp[i][0] = 1;
}
for (int j = 0; j < m; j++) {
dp[0][j] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
return dp[n - 1][m - 1];
}
}