Solution Code in c++


  • 0
    K
    class Solution {
    public:
        int uniquePaths(int m, int n) {
                int uniquePaths[m + 1][n + 1];
                for (int i = 0; i < m; i++) {
                    for (int j = 0; j < n; j++) {
                        uniquePaths[i][j] = 0;
                        if (i == 0 && j == 0) uniquePaths[i][j] = 1;
                        if (i > 0) uniquePaths[i][j] += uniquePaths[i-1][j];
                        if (j > 0) uniquePaths[i][j] += uniquePaths[i][j-1];
                    }
                }
                return uniquePaths[m-1][n-1];           
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.