File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-442 /2081-1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-442 /2081-1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-460 /2081-1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-460 /2081-1abc9c.svg )
5
5
![ problems-solved-python] ( https://img.shields.io/badge/Python-186/2081-1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
61
61
| 61 | [ Rotate List] ( https://leetcode.com/problems/rotate-list ) | [ ![ Java] ( assets/java.png )] ( src/RotateList.java ) | |
62
62
| 62 | [ Unique Paths] ( https://leetcode.com/problems/unique-paths ) | [ ![ Java] ( assets/java.png )] ( src/UniquePaths.java ) | |
63
63
| 63 | [ Unique Paths II] ( https://leetcode.com/problems/unique-paths-ii ) | [ ![ Java] ( assets/java.png )] ( src/UniquePathII.java ) | |
64
+ | 64 | [ Minimum Path Sum] ( https://leetcode.com/problems/minimum-path-sum ) | [ ![ Java] ( assets/java.png )] ( src/MinimumPathSum.java ) | |
64
65
| 66 | [ Plus One] ( https://leetcode.com/problems/plus-one ) | [ ![ Java] ( assets/java.png )] ( src/PlusOne.java ) [ ![ Python] ( assets/python.png )] ( python/plus_one.py ) | |
65
66
| 67 | [ Add Binary] ( https://leetcode.com/problems/add-binary ) | [ ![ Java] ( assets/java.png )] ( src/AddBinary.java ) [ ![ Python] ( assets/python.png )] ( python/add_binary.py ) | |
66
67
| 69 | [ Sqrt(x)] ( https://leetcode.com/problems/sqrtx ) | [ ![ Java] ( assets/java.png )] ( src/Sqrtx.java ) [ ![ Python] ( assets/python.png )] ( python/sqrt.py ) | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/minimum-path-sum
2
+ // T: O(m * n)
3
+ // S: O(1)
4
+
5
+ public class MinimumPathSum {
6
+ public int minPathSum (int [][] grid ) {
7
+ final int rows = grid .length , columns = grid [0 ].length ;
8
+
9
+ // last row
10
+ for (int column = columns - 2 ; column >= 0 ; column --) {
11
+ grid [rows - 1 ][column ] += grid [rows - 1 ][column + 1 ];
12
+ }
13
+
14
+ // last column
15
+ for (int row = rows - 2 ; row >= 0 ; row --) {
16
+ grid [row ][columns - 1 ] += grid [row + 1 ][columns - 1 ];
17
+ }
18
+
19
+ for (int row = rows - 2 ; row >= 0 ; row --) {
20
+ for (int column = columns - 2 ; column >= 0 ; column --) {
21
+ grid [row ][column ] += Math .min (grid [row + 1 ][column ], grid [row ][column + 1 ]);
22
+ }
23
+ }
24
+
25
+ return grid [0 ][0 ];
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments