8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 01eeca7 commit dd07bc7Copy full SHA for 10000 dd07bc7
MinimumPathSum/MinimumPathSum.cpp
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ int minPathSum(vector<vector<int>>& grid) {
4
+ // Start typing your C/C++ solution below
5
+ // DO NOT write int main() function
6
+
7
+ int m = grid.size();
8
+ if (m == 0) return 0;
9
+ int n = grid[0].size();
10
11
+ vector<vector<int>> dp(m, vector<int>(n, 0));
12
13
+ dp[0][0] = grid[0][0];
14
+ for (int i = 1; i < m; i++)
15
+ dp[i][0] = dp[i-1][0] + grid[i][0];
16
+ for (int j = 1; j < n; j++)
17
+ dp[0][j] = dp[0][j-1] + grid[0][j];
18
19
+ for (int i = 1; i < m; i++) {
20
21
+ dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + grid[i][j];
22
+ }
23
+ return dp[m-1][n-1];
24
25
+};
0 commit comments