当前位置:网站首页>剑指offer基础版 --- 第22天
剑指offer基础版 --- 第22天
2022-07-31 05:09:00 【米兰的小红黑】

class Solution {
public int[] singleNumbers(int[] nums) {
int ret = 0;
for(int num : nums){
ret = ret ^ num;
}
int target = 1;
while((target & ret) == 0){
target = target << 1;
}
int a = 0;
int b = 0;
for(int num : nums){
if((num & target) == 0){
a = a ^ num;
}else{
b = b ^ num;
}
}
return new int[]{
a,b};
}
}

class Solution {
public int singleNumber(int[] nums) {
int[] counts = new int[32];
for(int num : nums) {
for(int j = 0; j < 32; j++) {
counts[j] += num & 1;
num >>>= 1;
}
}
int res = 0, m = 3;
for(int i = 0; i < 32; i++) {
res = (counts[i] % m) << i | res;
}
return res;
}
}
边栏推荐
- pytorch中的一维、二维、三维卷积操作
- Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
- Centos7 install mysql5.7 steps (graphical version)
- A complete introduction to JSqlParse of Sql parsing and conversion
- Unity mobile game performance optimization series: performance tuning for the CPU side
- numpy和pytorch中的元素拼接操作:stack,concatenat,cat
- Sql解析转换之JSqlParse完整介绍
- 【LeetCode-SQL每日一练】——2. 第二高的薪水
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- 分布式事务处理方案大 PK!
猜你喜欢
随机推荐
Interviewer, don't ask me to shake hands three times and wave four times again
分布式事务处理方案大 PK!
如何将项目部署到服务器上(全套教程)
MySQL优化:从十几秒优化到三百毫秒
Multiple table query of sql statement
工作流编排引擎-Temporal
mysql5.7.35安装配置教程【超级详细安装教程】
mysql 的简单运用命令
Shell重油常压塔模拟仿真与控制
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
Reference code series_1. Hello World in various languages
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
docker安装postgresSQL和设置自定义数据目录
STM32——DMA
MYSQL一站式学习,看完即学完
【一起学Rust】Rust学习前准备——注释和格式化输出
The interviewer asked me TCP three handshake and four wave, I really
mysql uses on duplicate key update to update data in batches
SQL语句中对时间字段进行区间查询
Temporal介绍








