当前位置:网站首页>剑指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;
}
}
边栏推荐
- C语言指针详解
- Flink sink ES 写入 ES(带密码)
- 12 reasons for MySQL slow query
- 工作流编排引擎-Temporal
- MySQL-Explain详解
- Three oj questions on leetcode
- Summary of MySQL common interview questions (recommended collection!!!)
- 如何将项目部署到服务器上(全套教程)
- Unity Framework Design Series: How Unity Designs Network Frameworks
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
猜你喜欢

有了MVC,为什么还要DDD?

分布式事务处理方案大 PK!

快速掌握并发编程 --- 基础篇

MySQL事务隔离级别详解

Summary of MySQL common interview questions (recommended collection!!!)

Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构

DVWA installation tutorial (understand what you don't understand · in detail)

MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细

Interviewer, don't ask me to shake hands three times and wave four times again

CentOS7 - yum install mysql
随机推荐
有了MVC,为什么还要DDD?
剑指offer专项突击版 ---- 第2天
.NET-9. A mess of theoretical notes (concepts, ideas)
MySQL forgot password
matlab simulink欠驱动水面船舶航迹自抗扰控制研究
mysql uses on duplicate key update to update data in batches
Flink sink ES 写入 ES(带密码)
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
MySQL事务(transaction) (有这篇就足够了..)
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
Minesweeper game (written in c language)
工作流编排引擎-Temporal
Summary of MySQL common interview questions (recommended collection!!!)
DVWA安装教程(懂你的不懂·详细)
MySQL_关于JSON数据的查询
Kubernetes加入集群的TOKEN值过期
三次握手与四次挥手
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
Centos7 install mysql5.7