1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/哪种连续子字符串更长 [longer-contiguous-segments-of-ones-than-zeros].html
2022-03-29 12:43:11 +08:00

52 lines
2.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个二进制字符串 <code>s</code> 。如果字符串中由 <code>1</code> 组成的 <strong>最长</strong> 连续子字符串 <strong>严格长于</strong><code>0</code> 组成的 <strong>最长</strong> 连续子字符串,返回 <code>true</code> ;否则,返回 <code>false</code><em> </em></p>
<ul>
<li>例如,<code>s = "<strong>11</strong>01<strong>000</strong>10"</code> 中,由 <code>1</code> 组成的最长连续子字符串的长度是 <code>2</code> ,由 <code>0</code> 组成的最长连续子字符串的长度是 <code>3</code></li>
</ul>
<p>注意,如果字符串中不存在 <code>0</code> ,此时认为由 <code>0</code> 组成的最长连续子字符串的长度是 <code>0</code> 。字符串中不存在 <code>1</code> 的情况也适用此规则。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "1101"
<strong>输出:</strong>true
<strong>解释:</strong>
<code>1</code> 组成的最长连续子字符串的长度是 2"<strong>11</strong>01"
<code>0</code> 组成的最长连续子字符串的长度是 1"11<strong>0</strong>1"
由 1 组成的子字符串更长,故返回 true 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "111000"
<strong>输出:</strong>false
<strong>解释:</strong>
<code>1</code> 组成的最长连续子字符串的长度是 3"<strong>111</strong>000"
<code> 0</code> 组成的最长连续子字符串的长度是 3"111<strong>000</strong>"
由 1 组成的子字符串不比由 0 组成的子字符串长,故返回 false 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "110100010"
<strong>输出:</strong>false
<strong>解释:</strong>
<code>1</code> 组成的最长连续子字符串的长度是 2"<strong>11</strong>0100010"
<code>0</code> 组成的最长连续子字符串的长度是 3"1101<strong>000</strong>10"
由 1 组成的子字符串不比由 0 组成的子字符串长,故返回 false 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 100</code></li>
<li><code>s[i]</code> 不是 <code>'0'</code> 就是 <code>'1'</code></li>
</ul>