Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.

Note: You can only move either down or right at any point in time.

思路:此题和前面几个机器人的题很相像。仅仅是变化了一点。详细代码和凝视例如以下:

public class Solution {
public int minPathSum(int[][] grid) {
//动态规划思想
//选取到本点的最小值(从上方和左方来的最小值)
for(int i = 0; i < grid.length; i++)
for(int j = 0; j < grid[0].length; j++){
if(i > 0 && j > 0)//分三种情况,第二行第二列之后
grid[i][j] += Math.min(grid[i-1][j],grid[i][j-1]);
else if(i == 0 && j > 0)//第一行
grid[i][j] += grid[i][j-1];
else if(i > 0 && j==0)//第一列
grid[i][j] += grid[i-1][j];
}
//返回最后一个值
return grid[grid.length-1][grid[0].length-1];
}
}

leetCode 64.Minimum Path Sum (最短路) 解题思路和方法的更多相关文章

  1. [LeetCode] 64. Minimum Path Sum 最小路径和

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  2. LeetCode 64. Minimum Path Sum(最小和的路径)

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  3. LeetCode 64 Minimum Path Sum

    Problem: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom ri ...

  4. C#解leetcode 64. Minimum Path Sum

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  5. [leetcode]64. Minimum Path Sum最小路径和

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  6. [leetcode] 64. Minimum Path Sum (medium)

    原题 简单动态规划 重点是:grid[i][j] += min(grid[i][j - 1], grid[i - 1][j]); class Solution { public: int minPat ...

  7. leecode 每日解题思路 64 Minimum Path Sum

    题目描述: 题目链接:64 Minimum Path Sum 问题是要求在一个全为正整数的 m X n 的矩阵中, 取一条从左上为起点, 走到右下为重点的路径, (前进方向只能向左或者向右),求一条所 ...

  8. 刷题64. Minimum Path Sum

    一.题目说明 题目64. Minimum Path Sum,给一个m*n矩阵,每个元素的值非负,计算从左上角到右下角的最小路径和.难度是Medium! 二.我的解答 乍一看,这个是计算最短路径的,迪杰 ...

  9. 【LeetCode】64. Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

随机推荐

  1. json2.js

    /* http://www.JSON.org/json2.js 2010-03-20 Public Domain. NO WARRANTY EXPRESSED OR IMPLIED. USE AT Y ...

  2. 【CODEFORCES】 C. Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. SVN Client API的.net 接口 SharpSvn介紹 Checkout操作实例

    Subversion是一個文件版本管理工具, 廣泛的被大家採用來作為源代碼版本管理. 已有的工具不管是其自帶的命令行工具還是Windows UI的tortoiseSVN等還是很方便實用的, 但是如果想 ...

  4. 【ODPS】UDF基础

     UDF全称User Defined Function,即用户自己定义函数.ODPS提供了非常多内建函数来满足用户的计算需求,同一时候用户还能够通过创建自己定义函数来满足 不同的计算需求. UDF ...

  5. linux杂谈(十一):LDAPserver的搭建

    1.LDAP简单介绍      今天我们来介绍LDAPserver的搭建和client的訪问,可是基本的问题在前者.首先我们要知道什么是LDAP.      在日常交谈中.你可能会听到有些人这么说:& ...

  6. IE浏览器上传图片预览兼容(IE 7 8 9 10 11)

    $("#file_upload").change(function () { var $file = $(this); ]; var windowURL = window.URL ...

  7. Linux HugePage特性

    Linux HugePage特性 HugePage,就是指的大页内存管理方式.与传统的4kb的普通页管理方式相比,HugePage为管理大内存(8GB以上)更为高效.本文描述了什么是HugePage, ...

  8. 华为终端开放实验室Android Beta 4测试能力上线

    ​​​7月26日,Android P Beta 4发布(即Android P DP5),此版本为开发者最后一个预览版本,也预示着Android P正式版即将与大家见面. 为保证开发者在正式版本来临前做 ...

  9. JIRA /mnt/server/atlassian-jira-6.3.6-standalone/bin/start-jira.sh

    JIRA 敏捷开发平台部署记录   分类: 敏捷开发   1.1 jira说明 JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪. ...

  10. Struts1标签

    Struts1 标签库  说明 Struts提供了五个标签库,即:HTML.Bean.Logic.Template和Nested. HTML 标签 : 用来创建能够和Struts 框架和其他相应的HT ...