GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/L064_Minimum_Path_Sum.java at master · likevson/LeetCode

Expand file tree

/

L064_Minimum_Path_Sum.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
35 lines (25 loc) · 611 Bytes
/

L064_Minimum_Path_Sum.java

Copy path

File metadata and controls

35 lines (25 loc) · 611 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.