An array of integers, all appear twice except one, find this number.
Page 1 of 1
An array of integers, all appear twice except one, find this number.
1____int unique_number(int a[], int l) {
2__________int q = a[0];
3__________for (int i=1; i<l; i++) q = q^a[i];
4__________return q;
5____}
2__________int q = a[0];
3__________for (int i=1; i<l; i++) q = q^a[i];
4__________return q;
5____}
viterbi- Posts : 32
Join date : 2011-09-03
Similar topics
» you have an array of integers, find the longest subarray which consists of numbers that can be arranged in a sequence
» Find the number of inversions in an array
» In an array there is one element which repeats more than n/2 times...find the number in 0(n) time and 0(1) space
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
» Given a magic number sum, to find if there are two numbers whose sum equals to the number
» Find the number of inversions in an array
» In an array there is one element which repeats more than n/2 times...find the number in 0(n) time and 0(1) space
» Given a sorted array find all possible |ai - aj| where ai,aj belongs to Array A. n^2 is obvious. Find a solution in O(N).
» Given a magic number sum, to find if there are two numbers whose sum equals to the number
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|