标签:
Given an array of integers, every element appears twice except for one. Find that single one.
非常简单的一道题。
直接相异或剩下的那个数就是答案。原理是两个相等的数异或的值为0。
1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int temp; 5 for(int i=0;i!=n;i++) 6 temp=temp^A[i]; 7 return temp; 8 } 9 };
标签:
原文地址:http://www.cnblogs.com/desp/p/4333878.html