114.Unique Paths

2017-07-22  本文已影响0人  博瑜
public class Solution {
/**
 * @param n, m: positive integer (1 <= n ,m <= 100)
 * @return an integer
 */
public int uniquePaths(int m, int n) {
    // write your code here 
    int[][] state = new int[m][n];
    for (int i = 0; i < n; i++) {
        state[0][i] = 1;
    }
    for (int i = 1; i < m; i++) {
        state[i][0] = 1;
    }
    
    for (int i = 1; i < m; i++) {
        for (int j = 1; j < n;j++) {
            state[i][j] = state[i - 1][j] + state[i][j - 1];
        }
    }
    return state[m - 1][n - 1];
}
}
上一篇下一篇

猜你喜欢

热点阅读