当前位置:网站首页>Bit operation in leetcode
Bit operation in leetcode
2022-06-11 22:22:00 【Donkey of the production team】
Bit operation classification
Logical bit operators
be located &
Only two are for 1
Only then 1
position or |
Just one for 1
for 1

Exclusive or ^
Only different Only then 1,
otherwise by 0.
According to the not

Displacement operators
Move left <<
A shift to the left can be seen as This number ride 2 了 
Move right >>
A shift to the left can be seen as This number except 2 了
But notice If This number Positive number , Left complement 0
If This number It's a negative number , Left complement 1.

actual combat leetcode
https://leetcode.cn/problems/add-two-integers/
2235 Sum of two numbers
Code
class Solution{
public int sum (int num1, int num2){
if (num2 == 0){
return num1;
}
int add_xor = num1 ^ num2; // sum result without carry
int add_carry = (num1 & num2) << 1; // summ reult only about carry
return sum(add_xor,add_carry);
}
}
Reference
https://www.bilibili.com/video/BV1YT4y117AH/?spm_id_from=333.788.recommend_more_video.0&vd_source=8d8fef6cad2875d6b6b4c08c3a9ac66d
边栏推荐
- C language implements eight sorts (1)
- 图的基本操作(C语言)
- Tkinter study notes (III)
- R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
- Go OS module
- [Matlab]二阶节约响应
- Implementation of sequencelist sequence table
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2
- The device is in use when win10 ejects USB
- STM32开发笔记112:ADS1258驱动设计——读寄存器
猜你喜欢

Maze problem in C language

仅需三步学会使用低代码ThingJS与森数据DIX数据对接

机器学习之线性回归简单实例

Matlab: solution of folder locking problem

What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)

Matplotlib和tkinter学习笔记(一)

Popular science | what are the types of NFT (Part 1)

MySQL事务简介

5.学城项目 支付宝支付

The device is in use when win10 ejects USB
随机推荐
R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
3.3 测试模块的命名规则
Dynamics 365 选项集操作
Analysis of the implementation principle of an open source markdown to rich text editor
图的基本操作(C语言)
Is it safe for qiniu business school to send Huatai account? Really?
[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials
If I take the college entrance examination again, I will study mathematics well!
Determine whether the linked list is palindrome structure
STM32开发笔记113:ADS1258驱动设计——读取温度值
6.项目上线
Tkinter study notes (IV)
The device is in use when win10 ejects USB
926. 将字符串翻转到单调递增
大学三年应该这样过
Start notes under the Astro Pro binocular camera ROS
Leetcode stack topic summary
3.3 naming rules of test modules
习题8-2 在数组中查找指定元素 (15 分)
判断链表是否为回文结构