Skip to content

Commit fc886c4

Browse files
committed
Unique Paths solution
1 parent f26f58f commit fc886c4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

unique-paths/PDKhan.cpp

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

0 commit comments

Comments
 (0)