Skip to content

Commit 28b7ea6

Browse files
committed
leetcode
1 parent 7835876 commit 28b7ea6

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
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

67
using namespace std;
78

8-
99
class 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
};

0 commit comments

Comments
 (0)