leetcode:Minimum Path Sum
来源:互联网 发布:淘宝网狗狗宠物店 编辑:程序博客网 时间:2024/06/07 01:55
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) { int row = grid.length; int col = grid[0].length; for(int i = 0; i < grid.length; ++i){ for(int j = 0; j < grid[0].length; ++j){ if(i == 0){ if(j != 0){ grid[i][j] += grid[i][j - 1]; } } else if(j == 0){ if(i != 0){ grid[i][j] += grid[i - 1][j]; } } else{ grid[i][j] += Math.min(grid[i - 1][j], grid[i][j - 1]); } } } return grid[row - 1][col - 1]; } }
0 0
- LeetCode: Minimum Path Sum
- LeetCode Minimum Path Sum
- LeetCode : Minimum Path Sum
- [Leetcode] Minimum Path Sum
- [LeetCode] Minimum Path Sum
- [Leetcode] Minimum Path Sum
- [LeetCode]Minimum Path Sum
- [leetcode]Minimum Path Sum
- LeetCode-Minimum Path Sum
- [leetcode] Minimum Path Sum
- LeetCode - Minimum Path Sum
- LeetCode:Minimum Path Sum
- leetcode minimum path sum
- 【leetcode】Minimum Path Sum
- 【LeetCode】Minimum Path Sum
- Leetcode: Minimum Path Sum
- Leetcode Minimum Path Sum
- LeetCode Minimum Path Sum
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- 理解 Java 的 GC 与 幽灵引用
- 线程、锁
- LeetCode:Merge Sorted Array
- 10个帮你减压放松的网站
- leetcode:Minimum Path Sum
- 各项异性扩散滤波 -- OpenCV实现
- No rule to make target `/Users/apple/Desktop/Jayon/Cocos2dx/cocos2d-2.0-x-2.
- Codeforces Round #274 (Div. 2) 解题报告
- Redis源码解析(十五)--- aof-append only file解析
- ZOJ 1109 ————————字典树基础
- windows编程学习笔记(1)创建窗口与消息循环
- 广度优先搜索 入门:抓住那头牛
- LeetCode 二叉树的最小深度