File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,394 LeetCode solutions in JavaScript
1
+ # 1,395 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
966
966
1261|[ Find Elements in a Contaminated Binary Tree] ( ./solutions/1261-find-elements-in-a-contaminated-binary-tree.js ) |Medium|
967
967
1262|[ Greatest Sum Divisible by Three] ( ./solutions/1262-greatest-sum-divisible-by-three.js ) |Medium|
968
968
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|
969
970
1267|[ Count Servers that Communicate] ( ./solutions/1267-count-servers-that-communicate.js ) |Medium|
970
971
1268|[ Search Suggestions System] ( ./solutions/1268-search-suggestions-system.js ) |Medium|
971
972
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|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments