Skip to content

Commit eeb5213

Browse files
committed
Add solution #1266
1 parent 14c045d commit eeb5213

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,394 LeetCode solutions in JavaScript
1+
# 1,395 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -966,6 +966,7 @@
966966
1261|[Find Elements in a Contaminated Binary Tree](./solutions/1261-find-elements-in-a-contaminated-binary-tree.js)|Medium|
967967
1262|[Greatest Sum Divisible by Three](./solutions/1262-greatest-sum-divisible-by-three.js)|Medium|
968968
1263|[Minimum Moves to Move a Box to Their Target Location](./solutions/1263-minimum-moves-to-move-a-box-to-their-target-location.js)|Hard|
969+
1266|[Minimum Time Visiting All Points](./solutions/1266-minimum-time-visiting-all-points.js)|Easy|
969970
1267|[Count Servers that Communicate](./solutions/1267-count-servers-that-communicate.js)|Medium|
970971
1268|[Search Suggestions System](./solutions/1268-search-suggestions-system.js)|Medium|
971972
1269|[Number of Ways to Stay in the Same Place After Some Steps](./solutions/1269-number-of-ways-to-stay-in-the-same-place-after-some-steps.js)|Hard|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 1266. Minimum Time Visiting All Points
3+
* https://leetcode.com/problems/minimum-time-visiting-all-points/
4+
* Difficulty: Easy
5+
*
6+
* On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the
7+
* minimum time in seconds to visit all the points in the order given by points.
8+
*
9+
* You can move according to these rules:
10+
* - In 1 second, you can either:
11+
* - move vertically by one unit,
12+
* - move horizontally by one unit, or
13+
* - move diagonally sqrt(2) units (in other words, move one unit vertically then one unit
14+
* horizontally in 1 second).
15+
* - You have to visit the points in the same order as they appear in the array.
16+
* - You are allowed to pass through points that appear later in the order, but these do not
17+
* count as visits.
18+
*/
19+
20+
/**
21+
* @param {number[][]} points
22+
* @return {number}
23+
*/
24+
var minTimeToVisitAllPoints = function(points) {
25+
return points.reduce((steps, point, i) => steps + (!points[i + 1] ? 0 : Math.max(
26+
Math.abs(point[0] - points[i + 1][0]), Math.abs(point[1] - points[i + 1][1])
27+
)), 0);
28+
};

0 commit comments

Comments
 (0)