当前位置:网站首页>剑指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(更新中)
- Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
- With MVC, why DDD?
- 【LeetCode-SQL每日一练】——2. 第二高的薪水
- Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
- MySQL forgot password
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- 12个MySQL慢查询的原因分析
- STM32 - DMA
- DVWA installation tutorial (understand what you don't understand · in detail)
猜你喜欢
【LeetCode-SQL每日一练】——2. 第二高的薪水
Interviewer, don't ask me to shake hands three times and wave four times again
SQL行列转换
【一起学Rust】Rust学习前准备——注释和格式化输出
MySQL optimization slow log query
精解四大集合框架:List 核心知识总结
目标检测学习笔记
剑指offer专项突击版 ---第 5 天
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
mysql存储过程
随机推荐
The interviewer asked me TCP three handshake and four wave, I really
Kubernetes加入集群的TOKEN值过期
剑指offer专项突击版 ---第 5 天
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
Flink sink ES 写入 ES(带密码)
关于superset集成到自己的项目中
A complete introduction to JSqlParse of Sql parsing and conversion
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
可点击也可直接复制指定内容js
【LeetCode-SQL每日一练】——2. 第二高的薪水
剑指offer专项突击版 ---- 第 6 天
EasyExcel的简单读取操作
[MQ I can speak for an hour]
MySQL常见面试题汇总(建议收藏!!!)
MySQL window function
Sql解析转换之JSqlParse完整介绍
numpy和pytorch中的元素拼接操作:stack,concatenat,cat
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
matlab abel变换图片处理
mysql使用on duplicate key update批量更新数据