Skip to content

Instantly share code, notes, and snippets.

@Youngestdev
Created April 28, 2020 16:16
Show Gist options
  • Save Youngestdev/69fde8e3024ee97b3891920407dd6fc5 to your computer and use it in GitHub Desktop.
Save Youngestdev/69fde8e3024ee97b3891920407dd6fc5 to your computer and use it in GitHub Desktop.
class Solution {
public:
int uniquePaths(int m, int n) {
int dp[n][m];
dp[0][0] = 1;
if (m == 0 || n == 0) {
return 0;
}
for(int i = 0; i < n; i++) {
dp[i][0] = 1;
}
for (int j = 0; j < m; j++) {
dp[0][j] = 1;
}
for (int i = 1; i < n; i++){
for (int j = 1; j < m; j++){
dp[i][j] = dp[i-1][j] + dp[i][j-1];
}
}
return dp[n-1][m-1];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment