当前位置:网站首页>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
边栏推荐
- C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间
- The most detailed network counting experiment in history (2) -- rip experiment of layer 3 switch
- 【2022】将3D目标检测看作序列预测-Point2Seq: Detecting 3D Objects as Sequences
- MySQL syntax collation (3)
- Zero cost, zero foundation, build profitable film and television applet
- RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
- uIP1. 0 actively sent problem understanding
- Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es
- 山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
- [H264] hevc H264 parsing and frame rate setting of the old version of libvlc
猜你喜欢
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
php参考手册String(7.2千字)
【文本分类案例】(4) RNN、LSTM 电影评价倾向分类,附TensorFlow完整代码
antd dropdown + modal + textarea导致的textarea光标不可被键盘控制问题
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
Garbage collector and memory allocation strategy
精简CUDA教程——CUDA Driver API
Intuitive understanding of the essence of two-dimensional rotation
基于pytorch搭建GoogleNet神经网络用于花类识别
深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件
随机推荐
Kubernetes getting started to proficient - install openelb on kubernetes
【2022】将3D目标检测看作序列预测-Point2Seq: Detecting 3D Objects as Sequences
Strange problems in FrameLayout view hierarchy
goroutine
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
Shanda Wangan shooting range experimental platform project - personal record (V)
Electron入门教程4 —— 切换应用的主题
Strange passion
How to create bep-20 pass on BNB chain
IIS data conversion problem: 16bit to 24bit
Mysql database - single table query (I)
Steps to build a deep learning environment GPU
A simple (redisson based) distributed synchronization tool class encapsulation
Video understanding
Easy mock local deployment (you need to experience three times in a crowded time. Li Zao will do the same as me. Love is like a festival mock)
Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。
Some ideas about time-consuming needs assessment
Redis core technology and practice 1 - start with building a simple key value database simplekv
5 minutes to achieve wechat cloud applet payment function (including source code)
MySQL syntax collation (5) -- functions, stored procedures and triggers