当前位置:网站首页>剑指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;
}
}
边栏推荐
- Linux系统安装mysql(rpm方式安装)
- 质量小议12 -- 以测代评
- mysql5.7.35安装配置教程【超级详细安装教程】
- Temporal客户端模型
- ES source code API call link source code analysis
- Unity resources management series: Unity framework how to resource management
- 剑指offer专项突击版 ---- 第1天
- 面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
- Paginate the list collection and display the data on the page
- 关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
猜你喜欢
随机推荐
Flink sink redis 写入Redis
Linux系统安装mysql(rpm方式安装)
基于flask的三方登陆的流程
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
The interviewer asked me how to divide the database and the table?Fortunately, I summed up a set of eight-part essays
.NET-6.WinForm2.NanUI learning and summary
质量小议12 -- 以测代评
centos7安装mysql5.7
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Refinement of the four major collection frameworks: Summary of List core knowledge
DVWA安装教程(懂你的不懂·详细)
【一起学Rust】Rust的Hello Rust详细解析
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
【MQ我可以讲一个小时】
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Workflow番外篇
CentOS7 install MySQL graphic detailed tutorial
A complete introduction to JSqlParse of Sql parsing and conversion
Three oj questions on leetcode
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)