LeetCode 136. Single Number
2016-03-29 03:49
507 查看
Given an array of integers, every elements appears twice expect for one. Find the single one. Do it without using extra memory.
This problem can be solved using "set" or Hash Map. However, it is going to use extra memory space.
// we need to consider using bit manipulation. A ^ A = 0, 0 ^ A = A
This problem can be solved using "set" or Hash Map. However, it is going to use extra memory space.
// we need to consider using bit manipulation. A ^ A = 0, 0 ^ A = A
// Since in this array, every elements appears twice expect for one. We can use above equations. int onlyOne(vector<int> input) { // we need to first check the size of input. if(input.size() == 0) return 0; int result = 0; for(auto it : input) { result ^= it; } return result; }
相关文章推荐
- Android——RadioGroup和CheckBox
- 破解入门篇
- #Android Studio使用(1)#
- Java异常处理和设计
- Install and set up Gitlab CI Runner to use Docker
- Codeforces 658B Bear and Displayed Friends【set】
- Codeforces 658B Bear and Displayed Friends【set】
- JVM的内存区域划分
- 深入剖析Java中的装箱和拆箱
- 43. Multiply Strings
- Android——Button的颜色
- Java 如何有效地避免OOM:善于利用软引用和弱引用
- [Android]INSTALL_FAILED_NO_MATCHING_ABIS when installing apk
- PHP魔术常量
- 几款免费流程图制作软件
- 我与小娜(43):人脑与AlphaGo的奥秘
- java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app.Fragment.mNext
- PHP 自定义遍历-iterator迭代器
- 浅谈Java中的hashcode方法
- PHP静态延迟绑定 static