数组中只出现一次的数字

来源:互联网 发布:程序员教程 pdf 编辑:程序博客网 时间:2024/05/21 12:42
//典型亦或运算,这里直接上code,不解释#include <iostream>using namespace std;int only(int a[],int n){    int tmp = a[0];    int i = 1;    while(i<n)    {        tmp^=a[i];        ++i;    }    return tmp;}int main(){    int a[] = {1,1,2,2,3,3,4,};    cout<<only(a,7)<<endl;    return 0;}