MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Minimum Path Sum/Solution.java:17–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15*/
16
17class Solution {
18 public int minPathSum(int[][] grid) {
19 for(int i=1;i<grid.length;++i){
20 grid[i][0] += grid[i-1][0]; //moving down from top left and summing
21 }
22 for(int j=1;j<grid[0].length;++j){
23 grid[0][j] += grid[0][j-1]; //moving right from top left and summing
24 }
25 for(int i = 1;i<grid.length;++i){
26 for(int j = 1;j<grid[0].length;++j){
27 grid[i][j] += Math.min(grid[i][j-1],grid[i-1][j]);
28 }
29 }
30 return grid[grid.length-1][grid[0].length-1];
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected