当前位置:网站首页>剑指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中的一维、二维、三维卷积操作
- 基于flask的三方登陆的流程
- C语言的文件操作(一)
- 快速掌握并发编程 --- 基础篇
- 110 MySQL interview questions and answers (continuously updated)
- With MVC, why DDD?
- Minio upload file ssl certificate is not trusted
- Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
- MySQL-Explain详解
- CentOS7 - yum install mysql
猜你喜欢
随机推荐
mysql存储过程
Linux系统安装mysql(rpm方式安装)
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
C语言指针详解
Temporal介绍
对list集合进行分页,并将数据显示在页面中
可点击也可直接复制指定内容js
关于superset集成到自己的项目中
Distributed transaction processing solution big PK!
MySQL常见面试题汇总(建议收藏!!!)
关于LocalDateTime的全局返回时间带“T“的时间格式处理
有了MVC,为什么还要DDD?
MySQL optimization slow log query
centos7安装mysql5.7步骤(图解版)
Temporal对比Cadence
110道 MySQL面试题及答案 (持续更新)
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
mysql使用on duplicate key update批量更新数据
分布式事务处理方案大 PK!
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍