Lintcode 110 min path and lintcode110 path
Minimum path and
- Description
- Notes
- Data
- Evaluation
Given an m * n grid containing only non-negative integers, find a path from the upper left corner to the lower right corner to minimize the number and number.
Notes
You can only move one step down or to the right at the same time.
Have you ever encountered this question during a real interview? Yes, which company asked you this question? LinkedIn Amazon Airbnb Cryptic Studios Dropbox Epic Systems TinyCo Hedvig Uber Yelp Apple Yahoo Bloomberg Zenefits Twitter Microsoft Google Snapchat Facebook
Thank you for your feedback.
Example
TagDynamic Planning
Related Questions1 (dynamic-programming) easy digital triangle 26% 2 (dynamic-programming), (divide-and-conquer), (recursion) the maximum path and 25% in a medium-sized binary tree can only go down or to the right at a time. Therefore, this question can be updated by row or column.
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]; }};