0%

[題解]Leetcode 1266 Minimum Time Visiting All Points

1266 Minimum Time Visiting All Points

題目連結

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
int minTimeToVisitAllPoints(vector<vector<int>>& points) {
int n = points.size(),ans = 0;
vector<vector<int>> p = points;
for(int i = 0;i < n-1;i++){
ans += max(abs(p[i+1][0] - p[i][0]),abs(p[i+1][1] - p[i][1]));
}
return ans;
}
};