当前位置:网站首页>Sword finger offer 56 - I. number of occurrences in the array
Sword finger offer 56 - I. number of occurrences in the array
2022-06-13 04:26:00 【GRT has to keep working hard】
First review , If all but one number , The other numbers appear twice , So how to find the number that appears once ? The idea is to make the array elements different or .
class Solution {
public int[] singleNumbers(int[] nums) {
int z = 0;
for(int num:nums){
z^=num;// To obtain the z For two different numbers x And y The result of exclusive or . According to the nature of XOR ,z At least one of them is 1、 Next, find out this bit .
}
int m = 1;
while((z&m) == 0){
m<<=1;}
int x = 0,y = 0;
for(int i:nums){
if((i&m) == 0){
x^=i;}
else {
y^=i;}
}
return new int[]{
x,y};
}
}
边栏推荐
- Common encryption and decryption function encapsulation - AES encryption and decryption
- Online audio adjustment technology summary
- Introduction and use of ES6
- Single chip microcomputer: main index of a/d (analog-to-digital conversion)
- SCM signal generator program
- ACM ICPC
- Time format method on the official demo of uniapp
- knife4j aggregation 2.0.9支持路由文档自动刷新
- Small program imitating Taobao Jiugong grid sliding effect
- dumi 搭建文檔型博客
猜你喜欢
Analyse du principe de mise en œuvre d'un éditeur de texte open source markdown - to - rich
Et framework -22 creating serverinfo entities and events
Day45. data analysis practice (1): supermarket operation data analysis
Introduction and use of ES6
1.4.2 Capital Market Theroy
Reread the classic: end to end object detection with transformers
Redis
10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects
[kubernetes series] pod chapter actual operation
Knife4j aggregation 2.0.9 supports automatic refresh of routing documents
随机推荐
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
力扣刷题338.比特位计数
记录一次排查问题的经过——视频通话无法接起
Alipay native components (hotel time selection)
February 25, 2021 (Archaeology 12 year Landbridge provincial competition)
Get verification code
Catalan number
Sword finger offer II 022 Entry node of a link in a linked list
干预分析 + 伪回归
Common terms of electromagnetic compatibility
个人总结的MVP框架
Single chip microcomputer: basic concepts of a/d and d/a
Simple static web page + animation (small case)
环评图件制作-数据处理+图件制作
php开发博客系统的首页头部功能实现
Unity Shader 学习 004-Shader 调试 平台差异性 第三方调试工具
This Sedata uses multiple methods to dynamically modify objects and values in arrays. Object calculation properties
Single chip microcomputer: MODBUS multi computer communication program design
Ultra quicksort reverse sequence pair
1-72 convert string to decimal integer