-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path64.cpp
More file actions
executable file
·31 lines (31 loc) · 1007 Bytes
/
64.cpp
File metadata and controls
executable file
·31 lines (31 loc) · 1007 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
27
28
29
30
31
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int answer[2000][2000];
int minPathSum(vector<vector<int> >& grid) {
if (grid.size() == 0)
return 0;
for (int i = 0; i < grid.size(); i++)
for (int j = 0; j < grid[i].size(); j++)
answer[i][j] = 10000;
answer[0][0] = grid[0][0];
for (int i = 0; i <grid.size(); i++)
for (int j = 0; j <grid[i].size(); j++){
if (i == 0 && j == 0)
continue;
if (i == 0){
answer[i][j] = answer[i][j-1] + grid[i][j];
continue;
}
if (j == 0){
answer[i][j] = answer[i-1][j] + grid[i][j];
continue;
}
answer[i][j] = min(answer[i-1][j], answer[i][j-1]) + grid[i][j];
}
return answer[grid.size()][grid[0].size()];
}
};