Skip to content

Commit 6b25413

Browse files
authored
codewithdev#62 unique paths
frequently asked dp problem
1 parent d56df68 commit 6b25413

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int uniquePaths(int m, int n) {
4+
int dp[m][n];
5+
for(int i=0;i<n;i++){
6+
dp[0][i]=1;
7+
}
8+
9+
for(int i=1;i<m;i++){
10+
dp[i][0]=1;
11+
}
12+
13+
for(int i=1;i<m;i++){
14+
for(int j=1;j<n;j++){
15+
dp[i][j]=dp[i-1][j]+dp[i][j-1];
16+
}
17+
}
18+
19+
return dp[m-1][n-1];
20+
}
21+
};

0 commit comments

Comments
 (0)