<?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>scan Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/scan/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/scan/</link>
	<description></description>
	<lastBuildDate>Tue, 12 Jun 2018 05:40:18 +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>scan Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/scan/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 849. Maximize Distance to Closest Person</title>
		<link>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-849-maximize-distance-to-closest-person/</link>
					<comments>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-849-maximize-distance-to-closest-person/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 12 Jun 2018 05:39:42 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[scan]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2910</guid>

					<description><![CDATA[<p>Problem In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-849-maximize-distance-to-closest-person/">花花酱 LeetCode 849. Maximize Distance to Closest Person</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>In a row of <code>seats</code>, <code>1</code> represents a person sitting in that seat, and <code>0</code> represents that the seat is empty.</p>
<p>There is at least one empty seat, and at least one person sitting.</p>
<p>Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized.</p>
<p>Return that maximum distance to closest person.</p>
<div>
<p><strong>Example 1:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-1-1">[1,0,0,0,1,0,1]</span>
<strong>Output: </strong><span id="example-output-1">2</span>
<strong>Explanation: </strong>
If Alex sits in the second open seat (seats[2]), then the closest person has distance 2.
If Alex sits in any other open seat, the closest person has distance 1.
Thus, the maximum distance to the closest person is 2.</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-2-1">[1,0,0,0]</span>
<strong>Output: </strong><span id="example-output-2">3</span>
<strong>Explanation: </strong>
If Alex sits in the last seat, the closest person is 3 seats away.
This is the maximum distance possible, so the answer is 3.
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= seats.length &lt;= 20000</code></li>
<li><code>seats</code> contains only 0s or 1s, at least one <code>0</code>, and at least one <code>1</code>.</li>
</ol>
<h1><strong>Solution</strong></h1>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(1)</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 15 ms
class Solution {
public:
  int maxDistToClosest(vector&lt;int&gt;&amp; seats) {
    int n = seats.size();
    int prev = -1;
    int ans = 0;
    for (int i = 0; i &lt;= n; ++i) {
      if (i == n) ans = max(ans, n - prev - 1);
      else if (seats[i]) {
        if (prev == -1) ans = i;
        else ans = max(ans, (i - prev) / 2);
        prev = i;
      }
    }
    return ans;
  }
};</pre><p>&nbsp;</p>
</div>
</div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-849-maximize-distance-to-closest-person/">花花酱 LeetCode 849. Maximize Distance to Closest Person</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/algorithms/array/leetcode-849-maximize-distance-to-closest-person/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
