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 (English)/字符串中最大的 3 位相同数字(English) [largest-3-same-digit-number-in-string].html

50 lines
1.7 KiB
HTML

<p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>the <strong>maximum good </strong>integer as a <strong>string</strong> or an empty string </em><code>&quot;&quot;</code><em> if no such integer exists</em>.</p>
<p>Note:</p>
<ul>
<li>A <strong>substring</strong> is a contiguous sequence of characters within a string.</li>
<li>There may be <strong>leading zeroes</strong> in <code>num</code> or a good integer.</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;6<strong><u>777</u></strong>133339&quot;
<strong>Output:</strong> &quot;777&quot;
<strong>Explanation:</strong> There are two distinct good integers: &quot;777&quot; and &quot;333&quot;.
&quot;777&quot; is the largest, so we return &quot;777&quot;.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;23<strong><u>000</u></strong>19&quot;
<strong>Output:</strong> &quot;000&quot;
<strong>Explanation:</strong> &quot;000&quot; is the only good integer.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> num = &quot;42352338&quot;
<strong>Output:</strong> &quot;&quot;
<strong>Explanation:</strong> No substring of length 3 consists of only one unique digit. Therefore, there are no good integers.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= num.length &lt;= 1000</code></li>
<li><code>num</code> only consists of digits.</li>
</ul>