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)/负二进制数相加 [adding-two-negabinary-numbers].html
2022-03-29 12:43:11 +08:00

43 lines
1.6 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>给出基数为 <strong>-2</strong>&nbsp;的两个数&nbsp;<code>arr1</code>&nbsp;<code>arr2</code>,返回两数相加的结果。</p>
<p>数字以&nbsp;<em>数组形式</em><strong>&nbsp;</strong>给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列。例如,<code>arr&nbsp;= [1,1,0,1]</code>&nbsp;表示数字&nbsp;<code>(-2)^3&nbsp;+ (-2)^2 + (-2)^0 = -3</code><em>数组形式</em>&nbsp;中的数字 <code>arr</code> 也同样不含前导零:即&nbsp;<code>arr == [0]</code>&nbsp;&nbsp;<code>arr[0] == 1</code></p>
<p>返回相同表示形式的 <code>arr1</code><code>arr2</code> 相加的结果。两数的表示形式为:不含前导零、由若干 0 和 1 组成的数组。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr1 = [1,1,1,1,1], arr2 = [1,0,1]
<strong>输出:</strong>[1,0,0,0,0]
<strong>解释:</strong>arr1 表示 11arr2 表示 5输出表示 16 。
</pre>
<p><meta charset="UTF-8" /></p>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr1 = [0], arr2 = [0]
<strong>输出:</strong>[0]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr1 = [0], arr2 = [1]
<strong>输出:</strong>[1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<meta charset="UTF-8" />
<ul>
<li><code>1 &lt;= arr1.length,&nbsp;arr2.length &lt;= 1000</code></li>
<li><code>arr1[i]</code>&nbsp;&nbsp;<code>arr2[i]</code>&nbsp;都是&nbsp;<code>0</code>&nbsp;&nbsp;<code>1</code></li>
<li><code>arr1</code>&nbsp;&nbsp;<code>arr2</code>&nbsp;都没有前导0</li>
</ul>