GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/src/MinimumPathSum.java at master · LeBW/leetcode Expand file tree/ Copy pathMinimumPathSum.javaMore file actions 25 lines (25 loc) · 684 Bytes / Copy pathMinimumPathSum.javaFile metadata and controls25 lines (25 loc) · 684 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 /** * 64. Minimum Path Sum * @author LBW */ public class MinimumPathSum { public int minPathSum(int[][] grid) { int m = grid.length, n = grid[0].length; int[][] dp = new int[m][n]; // init dp[0][0] = grid[0][0]; for (int i = 1; i < m ;i++) { dp[i][0] = dp[i-1][0] + grid[i][0]; } for (int j = 1; j < n; j++) { dp[0][j] = dp[0][j-1] + grid[0][j]; } // fill the array for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { dp[i][j] = Math.min(dp[i-1][j], dp[i][j-1]) + grid[i][j]; } } return dp[m-1][n-1]; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |