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)/负二进制转换 [convert-to-base-2].html

38 lines
964 B
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>n</code> ,以二进制字符串的形式返回该整数的 <strong>负二进制(<code>base -2</code></strong>表示。</p>
<p><strong>注意,</strong>除非字符串就是&nbsp;<code>"0"</code>,否则返回的字符串中不能含有前导零。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 2
<strong>输出:</strong>"110"
<strong>解释:</strong>(-2)<sup>2</sup> + (-2)<sup>1</sup> = 2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3
<strong>输出:</strong>"111"
<strong>解释:</strong>(-2)<sup>2</sup> + (-2)<sup>1</sup> + (-2)<sup>0</sup> = 3
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 4
<strong>输出:</strong>"100"
<strong>解释:</strong>(-2)<sup>2</sup> = 4
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>