136. Single Number

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?

0和2个相同的数异或等于0  

1 int singleNumber(int* nums, int numsSize) {
2     int flag = 0;
3     int i;
4     for(i = 0; i < numsSize; i++)
5         flag ^= nums[i];
6     return flag;
7 }

 

posted @ 2016-05-15 19:58  米开朗菠萝  阅读(146)  评论(0)    收藏  举报