摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.[解题思路]与Unique Paths类似,只是把求路径数改成求最小路径和目标函数:sum[i][j] = grid[i][j] + Math.min(sum[i+1][j], sum 阅读全文
posted @ 2013-08-20 22:43 feiling 阅读(275) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0], [0,1, 阅读全文
posted @ 2013-08-20 22:09 feiling 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 1.DP bottom up 1 public int uniquePaths(int m, int n) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 int[][] steps = new int[m+2][n+2]; 5 for(int i = 0; i = 1; i--){13 for(int j = n; j >= 1; j--){14 steps[i... 阅读全文
posted @ 2013-08-20 17:15 feiling 阅读(467) 评论(0) 推荐(0) 编辑
摘要: Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space so 阅读全文
posted @ 2013-08-20 10:46 feiling 阅读(327) 评论(0) 推荐(0) 编辑
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you are a... 阅读全文
posted @ 2013-08-20 10:21 feiling 阅读(297) 评论(0) 推荐(0) 编辑