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)/插入 [insert-into-bits-lcci].html
2022-03-29 12:43:11 +08:00

24 lines
1.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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><code>M</code>,以及表示比特位置的 <code>i</code><code>j</code><code>i <= j</code>,且从 0 位开始计算)。</p>
<p>编写一种方法,使 <code>M</code> 对应的二进制数字插入 <code>N</code> 对应的二进制数字的第 <code>i ~ j</code> 位区域,不足之处用 <code>0</code> 补齐。具体插入过程如图所示。</p>
<p><img alt="" src="https://pic.leetcode-cn.com/1610104070-NuLVQi-05.01.gif" style="width: 267px; height: 200px;" /></p>
<p>题目保证从 <code>i</code> 位到 <code>j</code> 位足以容纳 <code>M</code> 例如: <code>M = 10011</code>,则 <code>ij</code> 区域至少可容纳 5 位。</p>
<p> </p>
<p><strong>示例1:</strong></p>
<pre>
<strong> 输入</strong>N = 1024(10000000000), M = 19(10011), i = 2, j = 6
<strong> 输出</strong>N = 1100(10001001100)
</pre>
<p><strong>示例2:</strong></p>
<pre>
<strong> 输入</strong> N = 0, M = 31(11111), i = 0, j = 4
<strong> 输出</strong>N = 31(11111)
</pre>