1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/三等分 [three-equal-parts].html
2022-03-29 12:43:11 +08:00

47 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>0</code><code>1</code> 组成的数组<meta charset="UTF-8" />&nbsp;<code>arr</code>&nbsp;,将数组分成 &nbsp;<strong>3&nbsp;个非空的部分</strong> ,使得所有这些部分表示相同的二进制值。</p>
<p>如果可以做到,请返回<strong>任何</strong>&nbsp;<code>[i, j]</code>,其中 <code>i+1 &lt; j</code>,这样一来:</p>
<ul>
<li><code>arr[0], arr[1], ..., arr[i]</code>&nbsp;为第一部分;</li>
<li><code>arr[i + 1], arr[i + 2], ..., arr[j - 1]</code>&nbsp;为第二部分;</li>
<li><code>arr[j], arr[j + 1], ..., arr[arr.length - 1]</code>&nbsp;为第三部分。</li>
<li>这三个部分所表示的二进制值相等。</li>
</ul>
<p>如果无法做到,就返回&nbsp;<code>[-1, -1]</code></p>
<p>注意,在考虑每个部分所表示的二进制时,应当将其看作一个整体。例如,<code>[1,1,0]</code>&nbsp;表示十进制中的&nbsp;<code>6</code>,而不会是&nbsp;<code>3</code>。此外,前导零也是<strong>被允许</strong>的,所以&nbsp;<code>[0,1,1]</code>&nbsp;<code>[1,1]</code>&nbsp;表示相同的值。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [1,0,1,0,1]
<strong>输出:</strong>[0,3]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [1,1,0,1,1]
<strong>输出:</strong>[-1,-1]</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>arr = [1,1,0,0,1]
<strong>输出:</strong>[0,2]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<meta charset="UTF-8" />
<ul>
<li><code>3 &lt;= arr.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>arr[i]</code>&nbsp;&nbsp;<code>0</code>&nbsp;&nbsp;<code>1</code></li>
</ul>