LeetCode 136. Single Number
2015-02-17 11:05
399 查看
只有一个数出现基数次(1次),其他数字出现欧数次(2次)
异或运算即可。
代码:
class Solution
{
public:
int singleNumber(int A[], int n)
{
int ret = 0;
for (int i = 0; i < n; ++ i)
{
ret ^= A[i];
}
return ret;
}
};
异或运算即可。
代码:
class Solution
{
public:
int singleNumber(int A[], int n)
{
int ret = 0;
for (int i = 0; i < n; ++ i)
{
ret ^= A[i];
}
return ret;
}
};
相关文章推荐
- LeetCode 136:Single Number
- [LeetCode By Python]136. Single Number
- 位运算——LeetCode 136.Single Number
- 【LeetCode】(136)Single Number (Easy)
- 【LeetCode】 136. Single Number
- LeetCode - 136. Single Number
- leetcode136: Single Number
- LeetCode(136) Single Number
- [LeetCode]: 136:Single Number
- LeetCode 136 Single Number
- [LeetCode136]Single Number
- LeetCode 136. Single Number
- Leetcode 136. Single Number
- LeetCode Problem 136:Single Number
- LeetCode 136 Single Number
- leetcode 136. Single Number
- 【leetcode】136. Single Number
- Leetcode-136 Single Number
- Leetcode题解 136. Single Number
- 【LeetCode】136. Single Number