当前位置:网站首页>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
边栏推荐
- Gossip: on greed
- A simple (redisson based) distributed synchronization tool class encapsulation
- First experience of using fluent canvas
- php参考手册String(7.2千字)
- Virtual machine performance monitoring and fault handling tools
- Understanding various team patterns in scrum patterns
- kibana 报错 server is not ready yet 可能的原因
- Prefer composition to inheritance
- An example of using JNI to directly access surface data
- Speculation on the way to realize the smooth drag preview of video editing software
猜你喜欢
Pdf reference learning notes
JVM的类加载过程
指针数组与数组指针的区分
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
山大网安靶场实验平台项目-个人记录(五)
Scrum Patterns之理解各种团队模式
Prefer composition to inheritance
C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
Zero base to build profit taking away CPS platform official account
随机推荐
山大网安靶场实验平台项目-个人记录(五)
MFC获取本机IP(网络通讯时用得多)
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.
TI DSP的 FFT与IFFT库函数的使用测试
Zero cost, zero foundation, build profitable film and television applet
Audio editing generation software
MySQL syntax collation (4)
goroutine
PHP reference manual string (7.2000 words)
5 minutes to achieve wechat cloud applet payment function (including source code)
Understanding various team patterns in scrum patterns
Lpc1768 optimization comparison of delay time and different levels
JVM的类加载过程
Speex Wiener filter and rewriting of hypergeometric distribution
C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间
A brief explanation of golang's keyword "competence"
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
antd dropdown + modal + textarea导致的textarea光标不可被键盘控制问题
Translation of audio signal processing and coding: Preface
Deep learning -- Summary of Feature Engineering