美文网首页
114.Unique Paths

114.Unique Paths

作者: 博瑜 | 来源:发表于2017-07-22 15:42 被阅读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];
    }
    }

    相关文章

      网友评论

          本文标题:114.Unique Paths

          本文链接:https://www.haomeiwen.com/subject/lfeukxtx.html