Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created December 24, 2018 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/7b1840f16510a53123530555f3279c86 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/7b1840f16510a53123530555f3279c86 to your computer and use it in GitHub Desktop.
class Solution {
public:
int uniquePaths(int m, int n) {
vector<vector<int>> DP(m, vector<int>(n, 0));
for(int i = 0; i< m; i++){
DP[i][0] = 1;
}
for(int j = 0; j < n; j++){
DP[0][j] = 1;
}
for(int i = 1; i < m; i++){
for(int j = 1; j < n; j++){
DP[i][j] = DP[i-1][j] + DP[i][j-1];
}
}
return DP[m-1][n-1];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment