标签:ice complex cep size run 异或操作 appear algorithm exce
题目描述:
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?
思路:
利用了异或操作的性质:
1,两个相同的数异或的结果为0
2,一个数和0异或的结果为这个数
代码:
1 class Solution {
2 public:
3 int singleNumber(int A[], int n) {
4
5 int result = 0;
6 for(int i = 0;i < n;i++)
7 {
8 result ^= A[i];
9 }
10 return result;
11
12 }
13 };
标签:ice complex cep size run 异或操作 appear algorithm exce
原文地址:https://www.cnblogs.com/zjuhaohaoxuexi/p/11773834.html