leetcode-----62. 不同路径

代码

class Solution {
public:
    int uniquePaths(int m, int n) {
        vector<vector<int>> f(n, vector<int>(m));

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (!i && !j) f[i][j] = 1;
                else {
                    if (i) f[i][j] += f[i - 1][j];
                    if (j) f[i][j] += f[i][j - 1];
                }
            }
        }
        return f[n - 1][m - 1];
    }
};
posted @ 2020-07-07 21:05  景云ⁿ  阅读(112)  评论(0编辑  收藏  举报