题1266、访问所有点的最小时间
程序员文章站
2022-07-15 11:22:15
...
一、题目1
二、思路
三、代码
public class T1266 {
public static void main(String[] args) {
System.out.println( minTimeToVisitAllPoints( new int[][]{ {1,1},{3,4},{-1,0} } ) ); //7
System.out.println( minTimeToVisitAllPoints( new int[][]{ {3,2},{-2,2} } ) ); //5
}
public static int minTimeToVisitAllPoints(int[][] points) {
int resut = 0;
for ( int i = 0; i < points.length-1; i++ ){
int x = Math.abs(points[i][0] - points[i+1][0]);
int y = Math.abs(points[i][1] - points[i+1][1]);
resut += x > y ? x :y;
}
return resut;
}
}
-
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/minimum-time-visiting-all-points
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 ↩︎
上一篇: LeetCode 矩阵置零(73题)