当前位置:网站首页>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;
}边栏推荐
- PyQt5 rapid development and actual combat 9.7 Automated testing of UI layer
- ECCV2022:在Transformer上进行递归,不增参数,计算量还少!
- Flutter键盘可见性
- mysql8, starttime的下一个值作为endtime的上一个值?
- 机器学习模型验证:被低估的重要一环
- 查看Oracle数据库的用户名和密码
- 代码随想录笔记_哈希_454四数相加II
- AI cocoa AI frontier introduction (7.31)
- The latest complete code: Incremental training using the word2vec pre-training model (two loading methods corresponding to two saving methods) applicable to various versions of gensim
- golang-gin-优雅重启
猜你喜欢

Ali on three sides: MQ message loss, repetition, backlog problem, how to solve?

Optimization of five data submission methods

抓住金三银四的尾巴,解锁程序员面试《刷题神器》

技能大赛dhcp服务训练题

MATLAB | 我也做了一套绘图配色可视化模板

中望3D 2023正式发布,设计仿真制造一体化缩短产品开发周期

报错:npm ERR code EPERM

技能大赛训练题:MS15_034漏洞验证与安全加固

golang-gin-优雅重启

Golang - gin - pprof - use and safety
随机推荐
EasyMock日记1[通俗易懂]
Centos7 install mysql5.7
C#控件StatusStrip使用
FastAPI encapsulates a generic response
拥塞控制,CDN,端到端
EXCEL如何快速拆分合并单元格数据
ADS与C#通信
技能大赛训练题:登录安全加固
IDEA的database使用教程(使用mysql数据库)
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
分布式锁有哪些,怎么实现(分布式锁的三种实现的对比)
生产力工具和插件
Introduction to the PartImageNet Semantic Part Segmentation dataset
基于改进YOLOv5的轻量化航空目标检测方法
JSP response对象简介说明
Samba 远程命令执行漏洞(CVE-2017-7494)
Centos7 install mysql5.7 steps (graphical version)
The latest complete code: Incremental training using the word2vec pre-training model (two loading methods corresponding to two saving methods) applicable to various versions of gensim
六石编程学:不论是哪个功能,你觉得再没用,会用的人都离不了,所以至少要做到99%
IDEA连接MySQL数据库并执行SQL查询操作