码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode1266. Minimum Time Visiting All Points

时间:2020-01-17 09:42:05      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:row   second   inf   seconds   最小   ota   return   定义   cond   

public int minTimeToVisitAllPoints(int[][] points) {
int rowLength = points.length; //获取行数
int count = 0;
for (int i = 0; i < rowLength - 1; i++) {
int min = -1; //定义横坐标与纵坐标之间最小值
int rowdif = Math.abs(points[i][0] - points[i + 1][0]);//行坐标值之间差值
int coldif = Math.abs(points[i][1] - points[i + 1][1]);//列左边之间差值
if (rowdif > coldif) { //行列之间差值取较小值是走斜步的步数
min = coldif;
} else {
min = rowdif;
}
count = count + min + Math.abs(rowdif - coldif);
}
// System.out.println("Total time="+count+"seconds");
return count;
}
我的解法速度不是很快

技术图片

 

 

 

好吧 我的两个值相加实际上就是两对差值里的最大值

Leetcode1266. Minimum Time Visiting All Points

标签:row   second   inf   seconds   最小   ota   return   定义   cond   

原文地址:https://www.cnblogs.com/chengxian/p/12204022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!