java.lang.Object
g1801_1900.s1869_longer_contiguous_segments_of_ones_than_zeros.Solution

public class Solution extends Object
1869 - Longer Contiguous Segments of Ones than Zeros.<p>Easy</p> <p>Given a binary string <code>s</code>, return <code>true</code> <em>if the <strong>longest</strong> contiguous segment of</em> <code>1</code>&lsquo;<em>s is <strong>strictly longer</strong> than the <strong>longest</strong> contiguous segment of</em> <code>0</code>&rsquo;<em>s in</em> <code>s</code>, or return <code>false</code> <em>otherwise</em>.</p> <ul> <li>For example, in <code>s = &quot;110100010&quot;</code> the longest continuous segment of <code>1</code>s has length <code>2</code>, and the longest continuous segment of <code>0</code>s has length <code>3</code>.</li> </ul> <p>Note that if there are no <code>0</code>&rsquo;s, then the longest continuous segment of <code>0</code>&rsquo;s is considered to have a length <code>0</code>. The same applies if there is no <code>1</code>&rsquo;s.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;1101&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>The longest contiguous segment of 1s has length 2: &ldquo;1101&rdquo;</p> <p>The longest contiguous segment of 0s has length 1: &ldquo;1101&rdquo;</p> <p>The segment of 1s is longer, so return true.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;111000&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>The longest contiguous segment of 1s has length 3: &ldquo;111000&rdquo;</p> <p>The longest contiguous segment of 0s has length 3: &ldquo;111000&rdquo;</p> <p>The segment of 1s is not longer, so return false.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;110100010&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>The longest contiguous segment of 1s has length 2: &ldquo;110100010&rdquo;</p> <p>The longest contiguous segment of 0s has length 3: &ldquo;110100010&rdquo;</p> <p>The segment of 1s is not longer, so return false.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • checkZeroOnes

      public boolean checkZeroOnes(String s)