当前位置:网站首页>Leetcode XOR operation
Leetcode XOR operation
2022-04-23 19:43:00 【Garrick doesn't want 996】
-
The rule of XOR operation is that the result of two identical numbers after XOR is 0,0 And others 0 The result after the number XOR of is the latter , And XOR operation supports commutative law and associative law , With these definitions, some algorithms can skillfully use XOR to solve problems .
-
Addition operation
XOR may not be used + Number to add two numbers , The result of the XOR of two numbers is the result of their addition
#include <iostream>
using namespace std;
int main() {
int single =20;
single ^=10;
cout<<single;
return 0;
}
The output is 30
- Only once
It is also the most magical function , It's also because of this question that I wrote this ,LeetCode Last question :
class Solution {
public:
int singleNumber(vector<int>& nums) {
int temp = 0;
for(int num:nums){
temp = temp ^ num;
}
return temp;
}
};
- XOR has three properties .
Any number and 0 Do exclusive or operations , The result is still the original number , namely a⊕0=a.
Any number is XOR with itself , The result is 0, namely a⊕a=0.
XOR operation satisfies the exchange law and the combination law , namely a⊕b⊕a=b⊕a⊕a=b⊕(a⊕a)=b⊕0=b
版权声明
本文为[Garrick doesn't want 996]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231942178113.html
边栏推荐
- Kubernetes entry to mastery - bare metal loadbalance 80 443 port exposure precautions
- MySQL 进阶 锁 -- MySQL锁概述、MySQL锁的分类:全局锁(数据备份)、表级锁(表共享读锁、表独占写锁、元数据锁、意向锁)、行级锁(行锁、间隙锁、临键锁)
- 仓库管理数据库系统设计
- The platinum library cannot search the debug process records of some projection devices
- MySQL syntax collation (2)
- @MapperScan与@Mapper
- Zero cost, zero foundation, build profitable film and television applet
- Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
- php参考手册String(7.2千字)
- C6748 software simulation and hardware test - with detailed FFT hardware measurement time
猜你喜欢
Kubernetes introduction to mastery - ktconnect (full name: kubernetes toolkit connect) is a small tool based on kubernetes environment to improve the efficiency of local test joint debugging.
Shanda Wangan shooting range experimental platform project - personal record (V)
NiO related Basics
C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
Decompile and get the source code of any wechat applet - just read this (latest)
ESP8266-入门第一篇
2021-2022-2 ACM training team weekly Programming Competition (8) problem solution
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
随机推荐
考试系统进入试卷优化思路
山大网安靶场实验平台项目-个人记录(五)
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
Speex Wiener filter and rewriting of hypergeometric distribution
MFCC: Mel频率倒谱系数计算感知频率和实际频率转换
Software College of Shandong University Project Training - Innovation Training - network security shooting range experimental platform (8)
MySQL数据库 - 数据库和表的基本操作(二)
Kibana reports an error server is not ready yet. Possible causes
Video understanding
Efficient serial port cyclic buffer receiving processing idea and code 2
MySQL数据库 - 单表查询(一)
Data analysis learning directory
Some speculation about the decline of adults' language learning ability
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Prefer composition to inheritance
如何在BNB鏈上創建BEP-20通證
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(八)
The usage of slice and the difference between slice and array
MySQL数据库 - 单表查询(二)
kibana 报错 server is not ready yet 可能的原因