mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
update
This commit is contained in:
44
leetcode/problem/minimum-time-visiting-all-points.html
Normal file
44
leetcode/problem/minimum-time-visiting-all-points.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p>
|
||||
|
||||
<p>You can move according to these rules:</p>
|
||||
|
||||
<ul>
|
||||
<li>In <code>1</code> second, you can either:
|
||||
|
||||
<ul>
|
||||
<li>move vertically by one unit,</li>
|
||||
<li>move horizontally by one unit, or</li>
|
||||
<li>move diagonally <code>sqrt(2)</code> units (in other words, move one unit vertically then one unit horizontally in <code>1</code> second).</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>You have to visit the points in the same order as they appear in the array.</li>
|
||||
<li>You are allowed to pass through points that appear later in the order, but these do not count as visits.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/1626_example_1.PNG" style="width: 500px; height: 428px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> points = [[1,1],[3,4],[-1,0]]
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation: </strong>One optimal path is <strong>[1,1]</strong> -> [2,2] -> [3,3] -> <strong>[3,4] </strong>-> [2,3] -> [1,2] -> [0,1] -> <strong>[-1,0]</strong>
|
||||
Time from [1,1] to [3,4] = 3 seconds
|
||||
Time from [3,4] to [-1,0] = 4 seconds
|
||||
Total time = 7 seconds</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> points = [[3,2],[-2,2]]
|
||||
<strong>Output:</strong> 5
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>points.length == n</code></li>
|
||||
<li><code>1 <= n <= 100</code></li>
|
||||
<li><code>points[i].length == 2</code></li>
|
||||
<li><code>-1000 <= points[i][0], points[i][1] <= 1000</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user