lintcode 110最小路径和
class Solution { public: /* * @param grid: a list of lists of integers * @return: An integer, minimizes the sum of all numbers along its path */ int minPathSum(vector<vector<int>> &grid) { // write your code here int x=grid.size(); int y=grid[x-1].size(); for(int i =0;i<x;i++){ for(int j=0;j<y;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]=grid[i][j]+min(grid[i-1][j],grid[i][j-1]); } } return grid[x-1][y-1]; } };