8000 2 · javasharper/leetcode@f8ea2f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f8ea2f6

Browse files
committed
2
1 parent c296b86 commit f8ea2f6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

UniquePaths/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+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
vector<vector<int>> dp(m, vector<int>(n, 0));
8+
for (int i = 0; i < m; i++)
9+
dp[i][0] = 1;
10+
for (int j = 0; j < n; j++)
11+
dp[0][j] = 1;
12+
for (int i = 1; i < m; i++) {
13+
for (int j = 1; j < n; j++)
14+
dp[i][j] = dp[i-1][j] + dp[i][j-1];
15+
}
16+
return dp[m-1][n-1];
17+
}
18+
};

0 commit comments

Comments
 (0)
0