We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 62db303 commit 0ce3cf5Copy full SHA for 0ce3cf5
Solutions/62(DP).cpp
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ int uniquePaths(int m, int n) {
4
+ vector<vector<int>> dp(m, vector<int> (n));
5
+ for(int i = m - 1; i >= 0; i--){
6
+ for(int j = n - 1; j >= 0; j--){
7
+ if(i == m - 1 && j == n - 1){
8
+ dp[i][j] = 1;
9
+ }
10
+ else if(i == m - 1){
11
+ dp[i][j] = dp[i][j + 1];
12
13
+ else if(j == n - 1){
14
+ dp[i][j] = dp[i + 1][j];
15
16
+ else{
17
+ dp[i][j] = dp[i + 1][j] + dp[i][j + 1];
18
19
20
21
+ return dp[0][0];
22
23
+};
24
+
25
+// Bottom-Up DP
0 commit comments