Skip to content

Commit c003d4d

Browse files
minimum time visiting all points
1 parent c578c91 commit c003d4d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
| 1243 | 🔒 [Array Transformation](https://leetcode.com/problems/array-transformation) | | |
328328
| 1252 | [Cells With Odd Values In Matrix](https://leetcode.com/problems/cells-with-odd-values-in-a-matrix) | [![Java](assets/java.png)](src/CellsWithOddValuesInMatrix.java) | |
329329
| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid) | [![Java](assets/java.png)](src/Shift2DGrid.java) | |
330-
| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | | |
330+
| 1266 | [Minimum Time Visiting All Points](https://leetcode.com/problems/minimum-time-visiting-all-points) | [![Java](assets/java.png)](src/MinimumTimeVisitingAllPoints.java) | |
331331
| 1271 | [Hexspeak](https://leetcode.com/problems/hexspeak) | | |
332332
| 1275 | [Find Winner On a Tic Tac Toe Game](https://leetcode.com/problems/find-winner-on-a-tic-tac-toe-game) | | |
333333
| 1281 | [Subtract the Product and Sum of Digits of a Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer) | | |

src/MinimumTimeVisitingAllPoints.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class MinimumTimeVisitingAllPoints {
2+
public int minTimeToVisitAllPoints(int[][] points) {
3+
int minTime = 0;
4+
for (int index = 0 ; index < points.length - 1 ; index++) {
5+
minTime += Math.max(
6+
Math.abs(points[index + 1][1] - points[index][1]),
7+
Math.abs(points[index + 1][0] - points[index][0])
8+
);
9+
}
10+
return minTime;
11+
}
12+
}

0 commit comments

Comments
 (0)