当前位置:网站首页>LeetCode只出现一次的数字
LeetCode只出现一次的数字
2022-07-31 13:26:00 【超爱学习芸】
题目要求:
给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
输入: [2,2,1] 输出: 1
输入:nums = [1,2,3,4] 输出:false
解题思路:
根据异或运算的规律,a^a = 0 ;0^a = a; a^b^a = a^a^b = b;
当数组进行异或运算后,只剩下单独的数字
代码展示:
int singleNumber(int* nums, int numsSize){
int k=0;
for(int i=0;i<numsSize;i++){
k^=nums[i];
}
return k;
}边栏推荐
- 机器学习模型验证:被低估的重要一环
- What should I do if selenium is reversed?
- Two methods of NameNode failure handling
- Golang - gin - pprof - use and safety
- CLion用于STM32开发
- IDEA如何运行web程序
- ECCV2022:在Transformer上进行递归,不增参数,计算量还少!
- How to quickly split and merge cell data in Excel
- Reasons and solutions for Invalid bound statement (not found)
- FastAPI encapsulates a generic response
猜你喜欢

Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"

Install the latest pytorch gpu version

Golang - gin - pprof - use and safety

深度剖析 Apache EventMesh 云原生分布式事件驱动架构

CentOS7 installation MySQL graphic detailed tutorial

Samba 远程命令执行漏洞(CVE-2017-7494)

PHP序列化:eval

操作符详解

Solution for browser hijacking by hao360

ADS与C#通信
随机推荐
Text similarity calculation (Chinese and English) detailed explanation of actual combat
C# control ToolStripProgressBar usage
Verilog——基于FPGA的贪吃蛇游戏(VGA显示)
Grab the tail of gold, silver and silver, unlock the programmer interview "Artifact of Brushing Questions"
Detailed explanation of network protocols and related technologies
IDEA如何运行web程序
Save and load numpy matrices and vectors, and use the saved vectors for similarity calculation
C#高级--委托
聊聊 SAP 产品 UI 上的消息显示机制
八大排序汇总及其稳定性
C#Assembly的使用
浏览器被hao360劫持解决办法
P5019 [NOIP2018 提高组] 铺设道路
为什么 wireguard-go 高尚而 boringtun 孬种
技能大赛训练题:MS15_034漏洞验证与安全加固
图像大面积缺失,也能逼真修复,新模型CM-GAN兼顾全局结构和纹理细节
清除浮动的四种方式及其原理理解
PyQt5 rapid development and actual combat 9.7 Automated testing of UI layer
基于模糊预测与扩展卡尔曼滤波的野值剔除方法
Flutter keyboard visibility