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/L064_Minimum_Path_Sum.java at master · likevson/LeetCode Expand file tree/ Copy pathL064_Minimum_Path_Sum.javaMore file actions 35 lines (25 loc) · 611 Bytes / Copy pathL064_Minimum_Path_Sum.javaFile metadata and controls35 lines (25 loc) · 611 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 26 27 28 29 30 31 32 33 34 35 package LeetCode; public class L064_Minimum_Path_Sum { public int minPathSum(int[][] grid) { if (grid == null || grid[0] == null) { return 0; } int m = grid.length; int n = grid[0].length; int[][] dp = new int[m][n]; dp[0][0] = grid[0][0]; for (int y = 1; y < n; y++) { dp[0][y] = dp[0][y - 1] + grid[0][y]; } for (int x = 1; x < m; x++) { dp[x][0] = dp[x - 1][0] + grid[x][0]; } for (int y = 1; y < n; y++) { for (int x = 1; x < m; x++) { int min = Math.min(dp[x - 1][y], dp[x][y - 1]); dp[x][y] = min + grid[x][y]; } } return dp[m - 1][n - 1]; } } |
| You are visitor 01402792 — 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. |