程式語言 - LeetCode - C++ - 62. Unique Paths



參考資訊:
https://algo.monster/liteproblems/62
https://www.cnblogs.com/grandyang/p/4353555.html

題目:


解答:

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

        dp[0][0] = 1;
        for (int row = 0; row < m; ++row) {
            for (int col = 0; col < n; ++col) {
                if (row > 0) {
                    dp[row][col] += dp[row - 1][col];
                }

                if (col > 0) {
                    dp[row][col] += dp[row][col - 1];
                }
            }
        }

        return dp[m - 1][n - 1];
    }
};