Skip to content

Commit 0ce3cf5

Browse files
Create 62(DP).cpp
1 parent 62db303 commit 0ce3cf5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Solutions/62(DP).cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy