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 @   米开朗菠萝  阅读(140)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示