반응형
https://leetcode.com/problems/minimum-time-visiting-all-points/
가로로 세로로, 대각선으로 한 칸씩 갈 수 있기 때문에
가로, 세로의 차 중에 큰 값으로 더 해주면 된다.
class Solution {
public:
int minTimeToVisitAllPoints(vector<vector<int>>& points) {
int ans=0;
for(int i =0;i<points.size()-1;i++){
if(abs(points[i][0]- points[i+1][0]) < abs(points[i][1]- points[i+1][1]) )
ans += abs(points[i][1]- points[i+1][1]);
else
ans += abs(points[i][0]- points[i+1][0]);
}
return ans;
}
};
http://www.cplusplus.com/reference/cstdlib/abs/
반응형
'IT > 알고리즘' 카테고리의 다른 글
29★] Leetcode 1013. Partition Array Into Three Parts With Equal Sum (0) | 2020.07.07 |
---|---|
28] Leetcode 1021. Remove Outermost Parentheses (0) | 2020.07.06 |
26★] Leetcode 1491. Average Salary Excluding the Minimum and Maximum Salary (0) | 2020.07.05 |
25★] Leetcode 1496. Path Crossing (0) | 2020.07.05 |
24] Leetcode 1502. Can Make Arithmetic Progression From Sequence (0) | 2020.07.05 |
댓글