Linked Url:https://leetcode.com/problems/single-number/

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example :
Input: [,,]
Output: 1
Example :
Input: [,,,,]
Output:

solution:

The method is xor option, principles is  : 0 xor 0 = 0; 0 xor 1 = 1;any  num xor itself  =  0,so we pass the array and xor its elements all,so the result  which is we want.

Ac code follow:

 class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = nums[];
for(int i = ;i < nums.size();++i)
res = nums[i]^res;
return res;
}
};

最新文章

  1. python3 实现简单的信用卡还款,取款转账功能V2
  2. UTF-8编码的字符串拆分成单字、获取UTF-8字符串的字符个数的代码及原理
  3. C语言 homework(4)
  4. 漫游Kafka设计篇之消息传输的事务定义
  5. CentOS下几种软件安装方式
  6. Android Studio rename module Can&#39;t rename root module
  7. python成长之路15
  8. 浅析Xilinx 三速以太网MAC IP核
  9. 文件比较与同步工具——FreeFileSync
  10. JDK1.8源码(十)——java.util.LinkedHashSet类
  11. JDK 5~8的特性对比
  12. 从mysql向HBase+Phoenix迁移数据的心得总结
  13. SQL Server进阶(十二)函数
  14. ng-cordova和cordova区别
  15. oracle中的对象创建及删除语句【原创】
  16. Spring Boot之初始化项目
  17. R基础-适合于纯小白
  18. 修改CSV中的某些值
  19. 十年WEB技术发展历程
  20. Java编程环境eclipse配置

热门文章

  1. MVC 创建强类型视图
  2. No module named import_export.admin Django python
  3. 将QuickReport报表保存为图片(使用TMetaFile和TMetafileCanvas)
  4. C# Windows服务以指定用户运行
  5. Ubuntu服务器搭建
  6. Unicode对象
  7. 可以用GetObjectProp来获取对象的属性
  8. Zookeeper 部署Zookeeper仲裁模式集群
  9. c# RedisHelper
  10. Windows线程生灭(图文并茂)