[Leetcode]Single Number
2016-11-10 14:06
381 查看
Given an array of integers, every element appears twice except
for one. Find that single one.
思路:
1. 使用HASH表存储每个数组元素出现的次数
2. 理解按位异或操作的本质原理
int singleNumber(int* nums, int numsSize) {
int result = 0;
int i = 0;
for (i = 0; i < numsSize; i ++){
result ^= nums[i];
}
return result;
}
采用位操作的方式比较精炼。
for one. Find that single one.
思路:
1. 使用HASH表存储每个数组元素出现的次数
2. 理解按位异或操作的本质原理
int singleNumber(int* nums, int numsSize) {
int result = 0;
int i = 0;
for (i = 0; i < numsSize; i ++){
result ^= nums[i];
}
return result;
}
采用位操作的方式比较精炼。
相关文章推荐
- LeetCode练习一:Single Number
- [LeetCode136]Single Number寻找一个数组里只出现一次的数
- LeetCode -- Single Number
- [LeetCode136]Single Number
- leetcode(十六)Single Number
- LeetCode 136 Single Number 出现一次的数字
- leetcode_136题——Single Number(哈希表hashtable,multiset,位运算)
- Leetcode-Single Number
- LeetCode136——Single Number
- leetcode笔记:Single Number
- leetcode 日经贴,Cpp code -Single Number
- leetcode:Single Number【Python版】
- [LeetCode]Single Number
- Leetcode_Alog.136- Single Number
- LeetCode 136. Single Number
- 【LeetCode-260】Single Number(C++)
- leetcode-Single Number
- leetcode 刷题报告 80 Single Number
- Single Number - leetcode
- 【Leetcode】Single Number