136. Single Number (Bit)
2015-12-06 07:12
288 查看
Given an 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?
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
class Solution { public: int singleNumber(int A[], int n) { int result = A[0]; int i = 1; while(i<n) { result = A[i] ^ result; //异或,相同为0 不同为1 i++; } return result; } };
相关文章推荐
- 普法知识(20):返老还童术?
- ssh登录报错-bash: fork: retry: Resource temporarily unavailable
- python核心编程-map处理多个序列
- excel排版:人工定制列宽时部分列宽参数
- python核心编程-map函数
- [LeetCode]Multiply Strings
- Mac 下 破解 sublime text 2 方法详解
- 从零开始学c语言教程
- C#设计模式——工厂方法模式
- [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
- ExtJS4.2学习(20)动态数据表格之前几章总结篇1(转)
- 对System.ComponentModel.DataAnnotations 的学习应用
- 【BLE】CC2541之SNV
- css3学习笔记(一)
- Angular JS 学习笔记四
- UVALive 6840 Sweet War (博弈dp)
- UVALive 6838 Flipping Parentheses (线段树)
- UVALive 6837 There is No Alternative (MST + LCA)
- UVALive 6833 Miscalculation (模拟)
- UVALive 6832 Bit String Reordering (模拟)