mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
41 lines
2.0 KiB
HTML
41 lines
2.0 KiB
HTML
<p>Given an integer <code>n</code> and an integer array <code>rounds</code>. We have a circular track which consists of <code>n</code> sectors labeled from <code>1</code> to <code>n</code>. A marathon will be held on this track, the marathon consists of <code>m</code> rounds. The <code>i<sup>th</sup></code> round starts at sector <code>rounds[i - 1]</code> and ends at sector <code>rounds[i]</code>. For example, round 1 starts at sector <code>rounds[0]</code> and ends at sector <code>rounds[1]</code></p>
|
|
|
|
<p>Return <em>an array of the most visited sectors</em> sorted in <strong>ascending</strong> order.</p>
|
|
|
|
<p>Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
<img alt="" src="https://assets.leetcode.com/uploads/2020/08/14/tmp.jpg" style="width: 433px; height: 341px;" />
|
|
<pre>
|
|
<strong>Input:</strong> n = 4, rounds = [1,3,1,2]
|
|
<strong>Output:</strong> [1,2]
|
|
<strong>Explanation:</strong> The marathon starts at sector 1. The order of the visited sectors is as follows:
|
|
1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)
|
|
We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> n = 2, rounds = [2,1,2,1,2,1,2,1,2]
|
|
<strong>Output:</strong> [2]
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> n = 7, rounds = [1,3,5,7]
|
|
<strong>Output:</strong> [1,2,3,4,5,6,7]
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= n <= 100</code></li>
|
|
<li><code>1 <= m <= 100</code></li>
|
|
<li><code>rounds.length == m + 1</code></li>
|
|
<li><code>1 <= rounds[i] <= n</code></li>
|
|
<li><code>rounds[i] != rounds[i + 1]</code> for <code>0 <= i < m</code></li>
|
|
</ul>
|