尧图网络科技YAOTU DIGITAL 获取报价
获取报价
首页 / 资讯中心 / 文章详情

LeetCode //C - 1266. Minimum Time Visiting All Points

发布时间:2026/9/27 23:50:38

资讯中心
01
ARTICLE

LeetCode //C - 1266. Minimum Time Visiting All Points

LeetCode //C - 1266. Minimum Time Visiting All Points
1266. Minimum Time Visiting All PointsOn a 2D plane, there are n points with integer coordinatesp o i n t s [ i ] [ x i , y i ] points[i] [x_i, y_i]points[i][xi​,yi​]. Returnthe minimum time in seconds to visit all the points in the order given by points.You can move according to these rules:In 1 second, you can either:move vertically by one unit,move horizontally by one unit, ormove diagonally sqrt(2) units (in other words, move one unit vertically then one unit horizontally in 1 second).You have to visit the points in the same order as they appear in the array.You are allowed to pass through points that appear later in the order, but these do not count as visits.Example 1:Input:points [[1,1],[3,4],[-1,0]]Output:7Explanation:One optimal path is [1,1] - [2,2] - [3,3] - [3,4] - [2,3] - [1,2] - [0,1] - [-1,0]Time from [1,1] to [3,4] 3 secondsTime from [3,4] to [-1,0] 4 secondsTotal time 7 secondsExample 2:Input:points [[3,2],[-2,2]]Output:5Constraints:points.length n1 n 100points[i].length 2-1000 points[i][0], points[i][1] 1000From: LeetCodeLink: 1266. Minimum Time Visiting All PointsSolution:Ideas:between two points, use diagonal moves as much as possible, so time is max(abs(dx), abs(dy)).Code:intminTimeToVisitAllPoints(int**points,intpointsSize,int*pointsColSize){inttime0;for(inti1;ipointsSize;i){intdxpoints[i][0]-points[i-1][0];intdypoints[i][1]-points[i-1][1];if(dx0)dx-dx;if(dy0)dy-dy;timedxdy?dx:dy;}returntime;}
02
RELATED NEWS

相关资讯

更多网站建设与数字化升级内容

03
WHY YAOTU

想打造同款高转化官网?

懂行业、懂生意,从建站到增长一站式陪跑

◈

场景化定制

不做模板站,围绕你的业务场景量身设计,小众不撞款。

◐

营销型架构

以转化目标组织内容与路径,让官网真正带来询盘。

▲

全周期服务

设计、开发、运营、运维一体,上线只是开始。

免费获取你的建站方案

留下需求,专属顾问 24 小时内为你输出方案建议。