首页 > 代码库 > LeetCode Unique Paths

LeetCode Unique Paths

//给定m*n的矩阵,从左上角走到左下角需要多少步?

class Solution {
public:
    int uniquePaths(int m, int n) {
        
        vector<vector<int> > table(m, vector<int>(n, 1));  
        for (int i = 1; i < m; i++)  
        {  
            for (int j = 1; j < n; j++)  
            {  
                table[i][j] = table[i-1][j] + table[i][j-1];  
            }  
        }  
        return table[m-1][n-1];  
    }
    
};

 

LeetCode Unique Paths