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 1:

Input: [2,2,1]
Output: 1

Example 2:

Input: [4,1,2,1,2]
Output: 4
var singleNumber = function(nums) {
let res = ;
for (let i = ; i < nums.length; i++) {
res = res ^ nums[i]
}
return res;
};

It uses XOR: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Bitwise_XOR

For example, 4 ^ 2

4: 0100

2: 0010

XOR

0110 => 6

But

2: 0010

2: 0010

XOR

0000 => 0

最新文章

  1. 移动混合应用HTML5数据查询优化
  2. Winform 生成不需要安装的exe可执行文件 ILMerge使用
  3. 学习hadoop遇到的问题
  4. nginx参数说明
  5. InterBase数据库迁移到MySQL(说明)
  6. NEC学习 ---- 布局 -三列,左侧自适应
  7. linux下查看一个进程的启动时间和运行时间
  8. 在线白板,基于socket.io的多人在线协作工具
  9. Bootstrap--组件之Glyphicons字体图标
  10. wget获取https资源
  11. 超声波 HC-SR04
  12. jq事件
  13. C# 设置Excel数据自适应行高、列宽的2种情况
  14. qml demo分析(text-字体展示)
  15. pta编程总结3
  16. 使用cmd命令导入SQL文件
  17. Python JSON 基本使用
  18. 免费工资总额管控系统-JXHR2016
  19. 删除SQL Server大容量日志的方法(转)
  20. Win10系列:UWP界面布局进阶6

热门文章

  1. TP5接口开发之异常处理接管
  2. keil 编译器V6 定义函数在ram中运行-和在指定地址定义常量
  3. Win10 UEFI 系统安装教程
  4. C#中datatable操作
  5. Nginx优化配置,轻松应对高并发
  6. vue中对象数组去重
  7. redis-存储命令
  8. InvalidOperationException: No file provider has been configured to process the supplied file.
  9. SpringBoot2.x搭建Eureka
  10. 微信小程序 - scroll-view的scroll-into-view属性 - 在页面打开后滚动到指定的项