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

38 lines
964 B
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>给你一个整数 <code>n</code> ,以二进制字符串的形式返回该整数的 <strong>负二进制(<code>base -2</code></strong>表示。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p><strong>注意,</strong>除非字符串就是&nbsp;<code>"0"</code>,否则返回的字符串中不能含有前导零。</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>n = 2
<strong>输出:</strong>"110"
<strong>解释:</strong>(-2)<sup>2</sup> + (-2)<sup>1</sup> = 2
2022-03-27 20:46:41 +08:00
</pre>
<p><strong>示例 2</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>n = 3
<strong>输出:</strong>"111"
<strong>解释:</strong>(-2)<sup>2</sup> + (-2)<sup>1</sup> + (-2)<sup>0</sup> = 3
2022-03-27 20:46:41 +08:00
</pre>
<p><strong>示例 3</strong></p>
2023-12-09 18:42:21 +08:00
<pre>
<strong>输入:</strong>n = 4
<strong>输出:</strong>"100"
<strong>解释:</strong>(-2)<sup>2</sup> = 4
2022-03-27 20:46:41 +08:00
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
2023-12-09 18:42:21 +08:00
<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>