Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int minimumTotal(List<List<Integer>> grid) {
- int numRows = grid.size();
- for(int row = 1; row < numRows; row++) {
- int leftWall = grid.get(row-1).get(0) + grid.get(row).get(0);
- grid.get(row).set(0, leftWall);
- int rightWall = grid.get(row-1).get(row-1) + grid.get(row).get(row);
- grid.get(row).set(row, rightWall);
- }
- for(int row = 2; row < numRows; row++) {
- for(int col = 1; col < row; col++) {
- int min = Math.min(grid.get(row-1).get(col), grid.get(row-1).get(col-1));
- int curr = min + grid.get(row).get(col);
- grid.get(row).set(col, curr);
- }
- }
- List<Integer> lastRow = grid.get(grid.size()-1);
- return Collections.min(lastRow);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement