-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlc64.cpp
More file actions
26 lines (22 loc) · 708 Bytes
/
lc64.cpp
File metadata and controls
26 lines (22 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <vector>
using namespace std;
class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
if (i == 0 && j == 0)
continue;
else if (i == 0)
grid[i][j] += grid[i][j - 1];
else if (j == 0)
grid[i][j] += grid[i - 1][j];
else
grid[i][j] += std::min(grid[i-1][j], grid[i][j-1]);
}
}
return grid[m-1][n-1];
}
};