class Solution {
public:
int minPathSum(vector<vector<int>>& grid) {
int xSize = grid[0].size();
int ySize = grid.size();
for (int x = 1; x < xSize; x++)
{
grid[0][x] = grid[0][x] + grid[0][x - 1];
}
for (int y = 1; y < ySize; y++)
{
grid[y][0] = grid[y][0] + grid[y - 1][0];
}
for (int y=1; y<ySize; y++)
for (int x = 1; x < xSize; x++)
{
grid[y][x] = grid[y][x] + std::min(grid[y][x - 1], grid[y - 1][x]);
}
return grid[ySize - 1][xSize - 1];
}
};
'C' 카테고리의 다른 글
영상처리 C++ 코드 - HOG+SVM을 활용한 보행자 검출 (0) | 2021.08.12 |
---|---|
c++ leetcode coin change code (0) | 2021.07.27 |
c++ leetcode DP min cost climing stairs code (0) | 2021.07.26 |
c++ leetcode climbing stairs DP solution(Top-down and bottom-up) (0) | 2021.07.24 |
c++ leetcode 939 minimum rectangle area o(n^2) solution code (0) | 2021.07.24 |