[leetcode]Unique Paths

Posted on 2013-07-27 20:12  冰天雪域  阅读(193)  评论(0编辑  收藏  举报
class Solution {
public:
    int uniquePaths(int m, int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<vector<int>> f(m, vector<int>(n, 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];
    }
};


Copyright © 2024 冰天雪域
Powered by .NET 9.0 on Kubernetes