Skip to content

Commit 52e1c81

Browse files
authored
62. Unique Paths
Dynamic Programming approach Time: O(N*M) Space: O(N*M)
1 parent b791d98 commit 52e1c81

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Dynamic-Programming/uniquePaths.cpp

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

0 commit comments

Comments
 (0)