<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>round Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/round/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/round/</link>
	<description></description>
	<lastBuildDate>Sun, 23 Aug 2020 17:51:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>round Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/round/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1560. Most Visited Sector in a Circular Track</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-1560-most-visited-sector-in-a-circular-track/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-1560-most-visited-sector-in-a-circular-track/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 23 Aug 2020 17:51:03 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[round]]></category>
		<category><![CDATA[simulation]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=7294</guid>

					<description><![CDATA[<p>Given an integer&#160;n&#160;and an integer array&#160;rounds.&#160;We&#160;have a circular track which consists of&#160;n&#160;sectors labeled from&#160;1&#160;to&#160;n. A marathon will be held on this track, the marathon consists&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1560-most-visited-sector-in-a-circular-track/">花花酱 LeetCode 1560. Most Visited Sector in a Circular Track</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given an integer&nbsp;<code>n</code>&nbsp;and an integer array&nbsp;<code>rounds</code>.&nbsp;We&nbsp;have a circular track which consists of&nbsp;<code>n</code>&nbsp;sectors labeled from&nbsp;<code>1</code>&nbsp;to&nbsp;<code>n</code>. A marathon will be held on this track, the marathon consists of&nbsp;<code>m</code>&nbsp;rounds. The&nbsp;<code>i<sup>th</sup></code>&nbsp;round starts at sector&nbsp;<code>rounds[i - 1]</code>&nbsp;and ends at sector&nbsp;<code>rounds[i]</code>. For example, round 1 starts at sector&nbsp;<code>rounds[0]</code>&nbsp;and ends at sector&nbsp;<code>rounds[1]</code></p>



<p>Return&nbsp;<em>an array of the most visited sectors</em>&nbsp;sorted in&nbsp;<strong>ascending</strong>&nbsp;order.</p>



<p>Notice that you&nbsp;circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).</p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/08/14/tmp.jpg" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><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 --&gt; 2 --&gt; 3 (end of round 1) --&gt; 4 --&gt; 1 (end of round 2) --&gt; 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>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 2, rounds = [2,1,2,1,2,1,2,1,2]
<strong>Output:</strong> [2]
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 7, rounds = [1,3,5,7]
<strong>Output:</strong> [1,2,3,4,5,6,7]
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>2 &lt;= n &lt;= 100</code></li><li><code>1 &lt;= m &lt;= 100</code></li><li><code>rounds.length == m + 1</code></li><li><code>1 &lt;= rounds[i] &lt;= n</code></li><li><code>rounds[i] != rounds[i + 1]</code>&nbsp;for&nbsp;<code>0 &lt;= i &lt; m</code></li></ul>



<h2><strong>Solution: Simulation</strong></h2>



<p>Time complexity: O(m*n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  vector&lt;int&gt; mostVisited(int n, vector&lt;int&gt;&amp; rounds) {
    vector&lt;int&gt; counts(n);
    counts[rounds[0] - 1] = 1;
    for (int i = 1; i &lt; rounds.size(); ++i)
      for (int s = rounds[i - 1]; ; ++s) {
        ++counts[s %= n];
        if (s == rounds[i] - 1) break;
      }
    const int max_count = *max_element(begin(counts), end(counts));
    vector&lt;int&gt; ans;
    for (int i = 0; i &lt; n; ++i)      
      if (counts[i] == max_count) ans.push_back(i + 1);    
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1560-most-visited-sector-in-a-circular-track/">花花酱 LeetCode 1560. Most Visited Sector in a Circular Track</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/simulation/leetcode-1560-most-visited-sector-in-a-circular-track/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
