<?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>contiguous Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/contiguous/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/contiguous/</link>
	<description></description>
	<lastBuildDate>Fri, 06 Aug 2021 04:14: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>contiguous Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/contiguous/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1869. Longer Contiguous Segments of Ones than Zeros</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-1869-longer-contiguous-segments-of-ones-than-zeros/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-1869-longer-contiguous-segments-of-ones-than-zeros/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 06 Aug 2021 04:13:23 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[contiguous]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8481</guid>

					<description><![CDATA[<p>Given a binary string&#160;s, return&#160;true&#160;if the&#160;longest&#160;contiguous segment of&#160;1s is&#160;strictly longer&#160;than the&#160;longest&#160;contiguous segment of&#160;0s in&#160;s. Return&#160;false&#160;otherwise. For example, in&#160;s = "110100010"&#160;the longest contiguous segment of&#160;1s has&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1869-longer-contiguous-segments-of-ones-than-zeros/">花花酱 LeetCode 1869. Longer Contiguous Segments of Ones than Zeros</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 a binary string&nbsp;<code>s</code>, return&nbsp;<code>true</code><em>&nbsp;if the&nbsp;<strong>longest</strong>&nbsp;contiguous segment of&nbsp;</em><code>1</code><em>s is&nbsp;<strong>strictly longer</strong>&nbsp;than the&nbsp;<strong>longest</strong>&nbsp;contiguous segment of&nbsp;</em><code>0</code><em>s in&nbsp;</em><code>s</code>. Return&nbsp;<code>false</code><em>&nbsp;otherwise</em>.</p>



<ul><li>For example, in&nbsp;<code>s = "<u>11</u>01<u>000</u>10"</code>&nbsp;the longest contiguous segment of&nbsp;<code>1</code>s has length&nbsp;<code>2</code>, and the longest contiguous segment of&nbsp;<code>0</code>s has length&nbsp;<code>3</code>.</li></ul>



<p>Note that if there are no&nbsp;<code>0</code>s, then the longest contiguous segment of&nbsp;<code>0</code>s is considered to have length&nbsp;<code>0</code>. The same applies if there are no&nbsp;<code>1</code>s.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "1101"
<strong>Output:</strong> true
<strong>Explanation:</strong>
The longest contiguous segment of 1s has length 2: "1101"
The longest contiguous segment of 0s has length 1: "1101"
The segment of 1s is longer, so return true.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "111000"
<strong>Output:</strong> false
<strong>Explanation:</strong>
The longest contiguous segment of 1s has length 3: "111000"
The longest contiguous segment of 0s has length 3: "111000"
The segment of 1s is not longer, so return false.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "110100010"
<strong>Output:</strong> false
<strong>Explanation:</strong>
The longest contiguous segment of 1s has length 2: "110100010"
The longest contiguous segment of 0s has length 3: "110100010"
The segment of 1s is not longer, so return false.
</pre>



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



<ul><li><code>1 &lt;= s.length &lt;= 100</code></li><li><code>s[i]</code>&nbsp;is either&nbsp;<code>'0'</code>&nbsp;or&nbsp;<code>'1'</code>.</li></ul>



<h2><strong>Solution: Brute Force</strong></h2>



<p>Write a function <span style="text-decoration: underline;"><em><strong>count</strong></em> </span>to count longest contiguous segment of m, return count(&#8216;1&#8217;) &gt; count(&#8216;0&#8217;)</p>



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



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  bool checkZeroOnes(string s) {
    auto count = [&amp;](char m) {
      int ans = 0;
      int l = 0;
      for (char c : s)
        if (c != m) l = 0;
        else ans = max(ans, ++l);      
      return ans;
    };
    return count('1') &gt; count('0');
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-1869-longer-contiguous-segments-of-ones-than-zeros/">花花酱 LeetCode 1869. Longer Contiguous Segments of Ones than Zeros</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/string/leetcode-1869-longer-contiguous-segments-of-ones-than-zeros/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
