当前位置:网站首页>剑指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;
}
}
边栏推荐
- MySQL事务(transaction) (有这篇就足够了..)
- 2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
- MySQL optimization: from ten seconds to three hundred milliseconds
- 分布式事务处理方案大 PK!
- Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
- CentOS7 —— yum安装mysql
- 剑指offer专项突击版 ---- 第 6 天
- C语言指针详解
- MySQL优化:从十几秒优化到三百毫秒
- Workflow番外篇
猜你喜欢
随机推荐
.NET-9. A mess of theoretical notes (concepts, ideas)
SQL injection of DVWA
对list集合进行分页,并将数据显示在页面中
快速掌握并发编程 --- 基础篇
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Shell重油常压塔模拟仿真与控制
Interviewer, don't ask me to shake hands three times and wave four times again
C语言教程(一)-准备
[mysql improves query efficiency] Mysql database query is slow to solve the problem
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
Unity resources management series: Unity framework how to resource management
数据集划分以及交叉验证法
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
为什么要用Flink,怎么入门使用Flink?
Linux系统安装mysql(rpm方式安装)
The monitoring of Doris study notes
Input length must be multiple of 8 when decrypting with padded cipher
剑指offer专项突击版 ---- 第 6 天
Flask 的初识








