剑指offer40
2024-09-26 14:25:31
class Solution {
public:
void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) {
if(data.size() <= )
return;
int resultOR = ;
for(int i = ;i < data.size();i++){
resultOR ^= data[i];
}
int resultIndex = FindFirst1(resultOR);
*num1 = ;
*num2 = ;
for(int i = ;i < data.size();i++){
if(Is1(data[i],resultIndex))
*num1 ^= data[i];
else
*num2 ^= data[i];
}
}
int FindFirst1(int num){
int index = ;
while((num & ) == ){
num = num >> ;
index++;
}
return index;
}
bool Is1(int number,int index){
number = number >> index;
return number & ;
}
};
(num&1) == 0这里必须打上括号,因为==的优先级高于&
return num&1可以不打括号
最新文章
- GIT常用命令笔记
- EXCEL处理大量数据的潜在风险
- PHP中的运算符---算术运算符、逻辑运算符、赋值运算符、比较运算符
- codeforces 500B.New Year Permutation 解题报告
- 【Clr in c#】泛型
- IE浏览器模式设置
- python声明文件编码,必须在文件的第一行或第二行
- bootstrap学习以及其插件
- Linux 安装Redis全过程日志
- ntpdate
- 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样
- vue_VueRouter 路由_路由器管理n个路由_并向路由组件传递数据_新标签路由_编程式路由导航
- gcc 找不到 boot python 链接库的问题: /usr/bin/ld: cannot find -lboost_python
- topcoder SRM642 div1 hard WheelofFortune
- PHP开发——数据类型
- EF-CodeFirst-数据迁移
- 精通Web Analytics 2.0 (12) 第十章:针对潜在的网站分析陷阱的最佳解决方案
- screen对象和history对象
- WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错
- 百度公共dns
热门文章
- cookie使用举例(添加购物车商品_移除购物车商品)
- linux C判断文件是否存在
- (转)shell实例浅谈之产生随机数七种方法
- (转)Python3.5 day3作业二:修改haproxy配置文件
- OpenCV细化算法简单解析
- 13、Selenium+python+API分类总结
- UVA 10462 —— Is There A Second Way Left?——————【最小生成树、kruskal、重边】
- oracle 找回被覆盖的存储过程
- 深入.NET框架。
- js中各种距离clientWidth