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 c
位操作, 找出数组中的单数, 双数是成对的数, 单数是只有一个数, 如 1 1 2 2 3 3 5 5 4
单数就是4
class Solution {
public:
int singleNumber(int A[], int n) {
int i=0;
int single = 0;
while(i!=n)
{
single = single^A[i];
i++;
}
return single;
}
};
每天早上叫醒你的不是闹钟,而是心中的梦~

浙公网安备 33010602011771号