File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed
Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change 11// 1266. Minimum Time Visiting All Points
22// https://leetcode.com/problems/minimum-time-visiting-all-points/
33
4- #include < bits/stdc++.h>
4+ #include < algorithm>
5+ #include < vector>
56
67using namespace std ;
78
8-
99class Solution {
10- public:
11- int minTimeToVisitAllPoints (vector<vector<int >>& points) {
12- int ans = 0 ;
13- for (int i = 1 ; i < points.size (); ++i) {
14- int d0 = abs (points[i][0 ] - points[i - 1 ][0 ]);
15- int d1 = abs (points[i][1 ] - points[i - 1 ][1 ]);
16- if (d0 < d1) swap (d0, d1);
17- ans += d0;
18- }
19- return ans;
10+ public:
11+ int minTimeToVisitAllPoints (vector<vector<int >>& points) {
12+ int ans = 0 ;
13+ for (size_t i = 1 ; i < points.size (); ++i) {
14+ int d0 = abs (points[i][0 ] - points[i - 1 ][0 ]);
15+ int d1 = abs (points[i][1 ] - points[i - 1 ][1 ]);
16+ ans += max (d0, d1);
2017 }
18+ return ans;
19+ }
2120};
You can’t perform that action at this time.
0 commit comments