goden0501

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

README

面试题 05.01.插入

1. 题目描述

给定两个整型数字 NM ,以及表示比特位置的 iji <= j ,且从 0 位开始计算)。

编写一种方法,使 M 对应的二进制数字插入 N 对应的二进制数字的第 i ~ j 位区域,不足之处用 0 补齐。具体插入过程如图所示。

题目保证从 i 位到 j 位足以容纳 M , 例如: M = 10011 ,则 i~j 区域至少可容纳 5 位。

 

示例1:


 输入:N = 1024(10000000000), M = 19(10011), i = 2, j = 6
 输出:N = 1100(10001001100)

示例2:


 输入: N = 0, M = 31(11111), i = 0, j = 4
 输出:N = 31(11111)

标签 位运算

2. 解题

  1. 取左段
  2. 取右端
  3. 组合左右段
  4. 组合左右段与中段

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL