Lintcode 110 min path and lintcode110 path

Source: Internet
Author: User
Tags lintcode

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];    }};

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.